Elasticsearch如何在通配符中使用multi_match

我有一个具有属性名称和姓氏的用户对象。我想使用一个查询来搜索这些字段,并且multi_match在文档中找到了该字段,但是我不知道如何将其与通配符一起正确使用。可能吗?

我尝试了multi_match查询,但没有成功:

{

"query": {

"multi_match": {

"query": "*mar*",

"fields": [

"user.name",

"user.surname"

]

}

}

}

回答:

或者,您可以query_string对通配符使用查询。

"query": {

"query_string": {

"query": "*mar*",

"fields": ["user.name", "user.surname"]

}

}

这将比在索引时使用nGram过滤器慢(请参阅我的其他答案),但是如果您正在寻找一种快速且肮脏的解决方案…

我也不确定您的映射,但是如果您使用user.name而不是name映射,则需要如下所示:

"your_type_name_here": {

"properties": {

"user": {

"type": "object",

"properties": {

"name": {

"type": "string"

},

"surname": {

"type": "string"

}

}

}

}

}

以上是 Elasticsearch如何在通配符中使用multi_match 的全部内容, 来源链接: utcz.com/qa/412820.html

回到顶部