gpt4 book ai didi

elasticsearch - 如何将AND条件与 'must'和 'should'结合?

转载 作者:行者123 更新时间:2023-12-02 22:34:35 25 4
gpt4 key购买 nike

我需要从满足以下2个条件的ES中返回文档:should子句中的conditionId至少应与文档的conditionId属性匹配,并且categoryId至少应与之一匹配。

我尝试了此查询,但这不起作用:

{
"query": {
"bool": {
"should": [
{
"match": {
"conditionIds": "5e24b2f02bd0d76df4615c82"
}
},
{
"match": {
"conditionIds": "5e24b2f02bd0d76df4615c82"
}
},
],
"filter": [
{
"query_string": {
"default_field": "name",
"query": "*"
}
}
],
"must": [
{
"match": {
"categoryIds": “fc57hj5-0bx-4sha-aw7u-c11cd32eec2a"
}
},
{
"match": {
"categoryIds": "d2c5a505-01bb-41ba-ad7e-c11cd32eec2a"
}
}
]
}
}
}

而我的文档架构:
                "conditionIds": [
"5e24b2f02bd0d76df4615c81"
],
"createdAt": "2020-05-08T19:07:11.756Z",
"categoryIds": [
"7b913ed0-54e0-4857-b114-92f65631b6a6"
],
"minPrice": 71.47,
"locations": [
{
"continent": "GLOBAL",
"lon": 0,
"lat": 0
}
],
"id": "c64d03d6-4248-416c-bc07-c42b50548e3b",
"maxPrice": 71.47,
"statusIds": [
"5e24b2f02bd0d76df4615c81"
],
"childrenCount": 1,
"updatedAt": "2020-05-08T19:07:11.756Z"
}

最佳答案

     {
"query": {
"bool": {
"should": {
"match": {
"conditionIds": {
"query": "5e24b2f02bd0d76df4615c82 5e24b2f02bd0d76df4615c82",
"operator": "OR"
}
}
},
"filter": [
{
"query_string": {
"default_field": "name",
"query": "*"
}
}
],
"must": {
"match": {
"categoryIds": {
"query": "d2c5a505-01bb-41ba-ad7e-c11cd32eec2a d2c5a505-01bb-41ba-ad7e-c11cd32eec2a",
"operator": "OR"
}
}
}
}
}
}


// OR Try the below one which matches most


{
"query": {
"bool": {
"filter": [
{
"query_string": {
"default_field": "name",
"query": "*"
}
}
],
"must": [
{
"match": {
"categoryIds": {
"query": "d2c5a505-01bb-41ba-ad7e-c11cd32eec2a d2c5a505-01bb-41ba-ad7e-c11cd32eec2a",
"operator": "OR"
}
}
},
{
"match": {
"conditionIds": {
"query": "5e24b2f02bd0d76df4615c82 5e24b2f02bd0d76df4615c82",
"operator": "OR"
}
}
}
]
}
}
}

关于elasticsearch - 如何将AND条件与 'must'和 'should'结合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61850923/

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