How to use standard search analyzer with keyword mapping?

若如初见. 提交于 2021-02-11 12:30:03

问题


I have to use search_analyzer not with text but with type keyword as below:

"properties":{

"email" : {
                "type" : "keyword",
                "analzer":"autocomplete",
                "search_analyzer":"standard"
          }
}

But actually I have below mappping:

 "properties":{

    "email" : {
                    "type" : "keyword",
              }
    }

回答1:


Analyzers only work with type text, not keyword. So you cannot define a search_analyzer on a keyword field. However, what you can do is to create a sub-field of type text like this:

PUT your-index/_mapping
{
  "properties": {
    "email": {
      "type": "keyword",
      "fields": {
        "analyzed": {
          "type": "text",
          "analyzer":"autocomplete",
          "search_analyzer":"standard"
        }
      }
    }
  }
}

When done, you need to update your data so that the email.analyzed field gets properly index. You can do it like this:

POST your-index/_update_by_query

When the call returns, the email.analyzed field will have been properly indexed with the autocomplete analyzer and you will be able to search on it using the standard search analyzer.



来源:https://stackoverflow.com/questions/61812756/how-to-use-standard-search-analyzer-with-keyword-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!