我使用elasticsearch ngram
"analysis": {
"filter": {
"desc_ngram": {
"type": "ngram",
"min_gram": 3,
"max_gram": 8
}
},
"analyzer": {
"index_ngram": {
"type": "custom",
"tokenizer": "keyword",
"filter": [ "desc_ngram", "lowercase" ]
},
"search_ngram": {
"type": "custom",
"tokenizer": "keyword",
"filter": "lowercase"
}
}
}我这里有两个对象
{
"name": "Shana Calandra",
"username": "shacalandra",
},
{
"name": "Shana Launer",
"username": "shalauner",
},并使用以下查询
{
query: {
match: {
_all: "Shana"
}
}
}当我使用这个查询进行搜索时,它会返回两个文档,但我不能在这里按单词的一部分进行搜索,例如,我不能在查询中使用"Shan“而不是"Shana”,因为它没有返回任何内容。
也许我的映射是错误的,我不能理解问题出在映射上还是查询上
发布于 2016-04-19 20:17:52
如果您指定
"mappings": {
"test": {
"_all": {
"index_analyzer": "index_ngram",
"search_analyzer": "search_ngram"
},对于_all字段的映射,它将会起作用。_all有自己的分析器,我怀疑你只为name和username使用了分析器,而不是_all。
https://stackoverflow.com/questions/36717776
复制相似问题