我试图在ElasticSearch中编写一个查询,该查询匹配单词中的连续字符。因此,如果我的索引包含“ John Doe”,则对于以下搜索,我仍然应该看到Elasticsearch返回的“ John Doe”。
到目前为止,我已经尝试了以下查询。
{
"query": {
"multi_match": {
"query": "term",
"operator": "OR",
"type": "phrase_prefix",
"max_expansions": 50,
"fields": [
"Field1",
"Field2"
]
}
}
}
但这也会返回不必要的匹配,例如当我键入john x时我仍然会得到“ John Doe”。
这对我有用。代替ngram,将数据索引为关键字。并使用通配符正则表达式匹配来匹配单词。
"query": {
"bool": {
"should": [
{
"wildcard": { "Field1": "*" + term + "*" }
},
{
"wildcard": { "Field2": "*" + term + "*" }
}
],
"minimum_should_match": 1
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句