问题
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