ElasticSearch如何使用multi_match与通配符 [英] ElasticSearch how to use multi_match with wildcard

查看:337
本文介绍了ElasticSearch如何使用multi_match与通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有对象User具有属性名称和姓氏。我想使用一个查询在这些字段中进行搜索,我在文档中找到了multi_match,但是我不知道如何正确地使用通配符。可能吗?



我尝试使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆