我的索引中包含以下文件字段priorityName的类型为search_as_you_type dataType我的用例就像我想用以下单词搜索文档:---
6个中只有前5个使用multi_match给我想要的结果我怎么有第6个用例,其中我们可以有不完整的单词而不是以第一个字符开头。
"_index": "priority",
"_type": "_doc",
"_id": "vaCI_HAB31AaC-t5TO9H",
"_score": 1,
"_source": { -
"priorityName": "What are you doing along Let's Go out"
}
},
{ -
"_index": "priority",
"_type": "_doc",
"_id": "vqCQ_HAB31AaC-t5wO8m",
"_score": 1,
"_source": { -
"priorityName": "what are you doing along let's go for shopping"
}
}
]
}```
re you
,您需要infix tokens
,默认情况下,它不包含在search_as_you_type数据类型中。我建议您创建一个自定义分析器,该分析器将创建中缀令牌并允许您匹配所有6个查询。 我已经创建了一个自定义分析器,并使用您的示例文档对其进行了测试,所有6个查询都给出了两个示例结果。
索引映射
{
"settings": {
"max_ngram_diff": 50,
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "ngram",
"min_gram": 1,
"max_gram": 8
}
},
"analyzer": {
"autocomplete_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"autocomplete_filter"
]
},
"lowercase_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"properties": {
"priorityName": {
"type": "text",
"analyzer": "autocomplete_analyzer",
"search_analyzer": "standard" --> not this
}
}
}
}
为示例文档建立索引
{ "priorityName" : "What are you doing along Let's Go out" } { "priorityName" : "what are you doing along let's go for shopping" }
搜索最后一个re you
的查询
{ "query": { "match" : { "priorityName" : "re you" } } }
和结果
"hits": [ { "_index": "ngram", "_type": "_doc", "_id": "1", "_score": 1.4652853, "_source": { "priorityName": "What are you doing along Let's Go out" } }, { "_index": "ngram", "_type": "_doc", "_id": "2", "_score": 1.4509768, "_source": { "priorityName": "what are you doing along let's go for shopping" } }
[其他查询也向我返回了两个文档,但不包括它们以缩短此答案的长度。]