V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
ThanksSirAlex
V2EX  ›  问与答

elasticsearch 搜索的时候怎么设置对搜索词不进行分词

  •  
  •   ThanksSirAlex · 2020-06-15 13:48:40 +08:00 · 2578 次点击
    这是一个创建于 1382 天前的主题,其中的信息可能已经有所发展或是发生改变。

    用了_analyze 接口,发现查询潮流的时候会这样

    {
      "tokens": [
        {
          "token": "潮",
          "start_offset": 0,
          "end_offset": 1,
          "type": "<IDEOGRAPHIC>",
          "position": 0
        },
        {
          "token": "流",
          "start_offset": 1,
          "end_offset": 2,
          "type": "<IDEOGRAPHIC>",
          "position": 1
        }
      ]
    }
    

    但是我不希望他对搜索词进行分词

    mapping 是这样的

    mappings: {
                       product: {
                         properties: {
                           title:      { type: 'text', boost: 100, index: 'not_analyzed' }, # analyzer: 'ik_smart', index: 'not_analyzed'
                           summary:    { type: 'text', boost: 10, index: 'not_analyzed' }, # analyzer: 'ik_smart', index: 'not_analyzed' },
                           content:    { type: 'text', boost: 10, index: 'not_analyzed' }, # analyzer: 'ik_smart', index: 'not_analyzed' },
                           class_name: { type: 'string', index: "not_analyzed" },
                           tags:       { type: 'text', boost: 100, index: 'not_analyzed' }, # analyzer: 'ik_smart', index: 'not_analyzed' },
                           date:       { type: 'date',  format: "yyyy-MM-dd'T'HH:mm:ss.SSSZZ"}
                         }
                       }
                     }
    
    9 条回复    2020-06-16 11:36:24 +08:00
    sss495088732
        1
    sss495088732  
       2020-06-15 13:53:39 +08:00
    type:"keyword",新版本好像没有 not_analyzed 这种说法了,仅 text 类型支持分词
    ThanksSirAlex
        2
    ThanksSirAlex  
    OP
       2020-06-15 14:21:57 +08:00
    @sss495088732 老项目了,用的还是 es5.5.3
    sss495088732
        3
    sss495088732  
       2020-06-15 16:55:35 +08:00
    @ThanksSirAlex 那就非常僵硬了 0.0
    wupeaking
        4
    wupeaking  
       2020-06-15 17:00:09 +08:00
    可以在建立 mapping 时再单独为这个字段创建一个不分词的属性
    zxc12300123
        5
    zxc12300123  
       2020-06-15 17:19:41 +08:00 via iPhone
    match_phrase
    ThanksSirAlex
        6
    ThanksSirAlex  
    OP
       2020-06-15 20:46:47 +08:00 via iPhone
    @zxc12300123 用了 match_phrase 一条结果都搜不到了,有点懵。。。
    optional
        7
    optional  
       2020-06-15 23:29:26 +08:00 via iPhone
    创建两个字段
    misaka19000
        8
    misaka19000  
       2020-06-15 23:37:49 +08:00
    看 ES 文档
    JRay
        9
    JRay  
       2020-06-16 11:36:24 +08:00
    在搜索字段的时候,在字段名称后面加上.keyword
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1462 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 314ms · UTC 17:24 · PVG 01:24 · LAX 10:24 · JFK 13:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.