怎么又是你

一个字段如何同时支持模糊匹配和精准匹配

Elasticsearch | 作者 TinaZhou | 发布于2020年04月27日 | 阅读数:3139

一个字符串字段 需要同时支持模糊匹配和精准匹配,也就是说两种分词类型1、keyword,2、ik_分词 ,
{
"testkeyword": {
"properties": {
"Name": {
"type": "string",
"fields": {
"text": {
"search_analyzer": "ik_smart",
"analyzer": "ik_max_word",
"type": "text",
"index_options": "offsets"
},
"keyword": {
"type": "keyword"
}
}
}
}
}
}
已邀请:

TinaZhou

赞同来自:

为什么不生效呢 

God_lockin

赞同来自:

啥版本的ES?type不能是string吧

waywu

赞同来自:

他这个看起来像是2.x的版本
PUT testindex
{
  "mappings": {
    "properties": {
      "name": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart", 
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

要回复问题请先登录注册