【发布时间】:2018-05-09 18:43:27
【问题描述】:
我正在寻找一种让 ES 使用多个分析器搜索数据的方法。 NGram 分析器和一种或几种语言分析器。
可能的解决方案是使用多字段并明确声明要为每个字段使用的分析器。
例如,设置以下映射:
"mappings": {
"my_entity": {
"properties": {
"my_field": {
"type": "text",
"fields": {
"ngram": {
"type": "string",
"analyzer": "ngram_analyzer"
},
"spanish": {
"type": "string",
"analyzer": "spanish"
},
"english": {
"type": "string",
"analyzer": "english"
}
}
}
}
}
}
问题在于我已经明确地将每个字段及其分析器写入搜索查询。 并且不允许使用“_all”进行搜索并使用多个分析器。
有没有办法让“_all”查询使用多个分析器? 像“_all.ngram”、“_all.spanish”这样的东西,并且不使用 copy_to 来复制数据?
是否可以将 ngram 分析器与西班牙语(或任何其他外语)结合起来制作一个自定义分析器? 我已经测试了以下设置,但这些设置不起作用:
PUT /ngrams_index
{
"settings": {
"number_of_shards": 1,
"analysis": {
"tokenizer": {
"ngram_tokenizer": {
"type": "nGram",
"min_gram": 3,
"max_gram": 3
}
},
"filter": {
"ngram_filter": {
"type": "nGram",
"min_gram": 3,
"max_gram": 3
},
"spanish_stop": {
"type": "stop",
"stopwords": "_spanish_"
},
"spanish_keywords": {
"type": "keyword_marker",
"keywords": ["ejemplo"]
},
"spanish_stemmer": {
"type": "stemmer",
"language": "light_spanish"
}
},
"analyzer": {
"ngram_analyzer": {
"type": "custom",
"tokenizer": "ngram_tokenizer",
"filter": [
"lowercase",
"spanish_stop",
"spanish_keywords",
"spanish_stemmer"
]
}
}
}
},
"mappings": {
"my_entity": {
"_all": {
"enabled": true,
"analyzer": "ngram_analyzer"
},
"properties": {
"my_field": {
"type": "text",
"fields": {
"analyzer1": {
"type": "string",
"analyzer": "ngram_analyzer"
},
"analyzer2": {
"type": "string",
"analyzer": "spanish"
},
"analyzer3": {
"type": "string",
"analyzer": "english"
}
}
}
}
}
}
}
GET /ngrams_index/_analyze
{
"field": "_all",
"text": "Hola, me llamo Juan."
}
返回:只有 ngram 结果,没有西班牙语分析
在哪里
GET /ngrams_index/_analyze
{
"field": "my_field.analyzer2",
"text": "Hola, me llamo Juan."
}
正确分析搜索字符串。
是否可以构建一个结合西班牙语和 ngram 的自定义分析器?
【问题讨论】:
标签: elasticsearch elasticsearch-5 analyzer