ElasticSearch如何使用multi_match与通配符 [英] ElasticSearch how to use multi_match with wildcard
问题描述
我尝试使用multi_match查询,但没有起作用:
查询:{
multi_match:{
query:* mar *,
fields:[
user .name,
user.surname
]
}
}
}
或者,您可以使用通配符 query_string
查询。
query:{
query_string:{
query:* mar *,
fields:[user.name,user.surname]
}
}
这比在索引时使用nGram过滤器慢(参见我的其他答案),但是如果你正在寻找一个快速而肮脏的解决方案...
此外,我不确定您的映射,但如果您使用 user.name
而不是名称
您的映射需要如下所示:
your_type_name_here:{
properties:{
user:{
type object,
properties:{
name:{
type:string
},
surname:{
type:string
}
}
}
}
}
I have object User with properties Name and Surname. I want search in these fields using one query, and I found multi_match in documentation, but I dont know how to properly use that with wildcard. Is it possible?
I tried with a multi_match query but it didn't work:
{
"query": {
"multi_match": {
"query": "*mar*",
"fields": [
"user.name",
"user.surname"
]
}
}
}
Alternatively you could use a query_string
query with wildcards.
"query": {
"query_string": {
"query": "*mar*",
"fields": ["user.name", "user.surname"]
}
}
This will be slower than using an nGram filter at index-time (see my other answer), but if you are looking for a quick and dirty solution...
Also I am not sure about your mapping, but if you are using user.name
instead of name
your mapping needs to look like this:
"your_type_name_here": {
"properties": {
"user": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"surname": {
"type": "string"
}
}
}
}
}
这篇关于ElasticSearch如何使用multi_match与通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!