如何在关键字映射中使用标准搜索分析器? [英] How to use standard search analyzer with keyword mapping?
问题描述
我必须不将search_analyzer用于文本,而应使用type关键字,如下所示:
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",
}
}
推荐答案
分析器只能使用 text
类型,而不能使用 keyword
类型.因此,您无法在关键字字段上定义 search_analyzer
.但是,您可以做的是创建一个文本类型的子字段,如下所示:
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"
}
}
}
}
}
完成后,您需要更新数据,以便 email.analyzed
字段正确地建立索引.您可以这样做:
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
当呼叫返回时, email.analyzed
字段将已使用 autocomplete
分析器正确索引,您将可以使用标准
搜索分析器.
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.
这篇关于如何在关键字映射中使用标准搜索分析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!