跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • elasticsearch 搜索的时候怎么设置对搜索词不进行分词
未分類
26 6 月 2020

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

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

資深大佬 : ThanksSirAlex 12

用了_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)

  • 資深大佬 : sss495088732

    type:”keyword”,新版本好像没有 not_analyzed 这种说法了,仅 text 类型支持分词

  • 主 資深大佬 : ThanksSirAlex

    @sss495088732 老项目了,用的还是 es5.5.3

  • 資深大佬 : sss495088732

    @ThanksSirAlex 那就非常僵硬了 0.0

  • 資深大佬 : wupeaking

    可以在建立 mapping 时再单独为这个字段创建一个不分词的属性

  • 資深大佬 : zxc12300123

    match_phrase

  • 主 資深大佬 : ThanksSirAlex

    @zxc12300123 用了 match_phrase 一条结果都搜不到了,有点懵。。。

  • 資深大佬 : optional

    创建两个字段

  • 資深大佬 : misaka19000

    看 ES 文档

  • 資深大佬 : JRay

    在搜索字段的时候,在字段名称后面加上.keyword

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具