gpt4 book ai didi

Elasticsearch : MultiMatch with "match a list of values"

转载 作者:行者123 更新时间:2023-11-29 02:57:37 25 4
gpt4 key购买 nike

如何在单个查询中组合使用 MultiMatch +“匹配值列表”。

即。我想根据字段列表查询名称 ["John","Bas","Peter"] ["first_name","Alias","nick_name","姓氏"]

-匹配值列表-

{
"query": {
"filtered" : {
"filter" : {
"terms": {
"first_name": ["John","Bas","Peter"]
}
}
}
}
}

-多重匹配-

{
"multi_match" : {
"query": "john",
"fields": ["first_name","Alias","nick_name","surname"]
}
}

最佳答案

您也可以为 multi_match 提供多个搜索词:

  "query": {
"multi_match": {
"query": "John Bas Peter",
"fields": [
"first_name",
"Alias",
"nick_name",
"surname"
]
}
}

此外,multi_match 有多种方法可以在内部实际转换查询:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#multi-match-types

如果您将 _validate API 与此结合使用,您可以看到 ES 是如何重新解释查询的:

GET /_validate/query?explain=true
{
"query": {
"multi_match": {
"query": "John Bas Peter",
"fields": [
"first_name",
"Alias",
"nick_name",
"surname"
]
}
}
}

以上给出:

   "explanations": [
{
"index": "test",
"valid": true,
"explanation": "((Alias:john Alias:bas Alias:peter) | (surname:john surname:bas surname:peter) | (nick_name:john nick_name:bas nick_name:peter) | (first_name:john first_name:bas first_name:peter))"
}
]

关于 Elasticsearch : MultiMatch with "match a list of values",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39171308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com