gpt4 book ai didi

elasticsearch - 在 Elasticsearch 中从内部查询获取值列表

转载 作者:行者123 更新时间:2023-12-02 23:43:20 26 4
gpt4 key购买 nike

我有一个像

{
"order_id" : 987,
"product_id": 1234,
"order_date": "2020-10-01",
"day of week": "Monday",
"currency": "USD"
..
},
{
"order_id" : 789,
"product_id": 4321,
"order_date": "2020-11-01",
"day of week": "Monday",
"currency": "USD"
..
}
现在我想要所有包含的order_id的所有列表/数组
  • 货币不为空
  • “星期几”是“星期一”

  • 对于我在搜索“order_id”的“条款”中的内部查询
    {
    "size": 0,
    "query": {
    "bool": {
    "filter": [
    {
    "terms": {
    "order_id": [
    **{
    "match": {
    "day of week": "Monday"
    }
    },
    {
    "exists": {
    "field": "currency"
    }
    }**
    ]
    }
    },
    {
    "exists": {
    "field": "order_date"
    }
    }]
    }
    }
    ..
    ..
    }
    我想要查询所有order_id的列表,而不是现有的内部查询(粗体)。

    最佳答案

    在下面的搜索查询中进行尝试,并引用Boolean query上的ES官方文档

    Query to find list/array of all order_id(s) which holds

    1. currency is not null
    2. "day of week" is 'Monday'

    添加具有相同索引数据的工作示例并采用默认映射。
    搜索查询:
    {
    "query": {
    "bool": {
    "filter": [
    {
    "term": {
    "day of week.keyword": "Monday"
    }
    },
    {
    "exists": {
    "field": "currency"
    }
    }
    ]
    }
    }
    }
    搜索结果:
    "hits": [
    {
    "_index": "my-index",
    "_type": "_doc",
    "_id": "1",
    "_score": 0.0,
    "_source": {
    "order_id": 987,
    "product_id": 1234,
    "order_date": "2020-10-01",
    "day of week": "Monday",
    "currency": "USD"
    }
    },
    {
    "_index": "my-index",
    "_type": "_doc",
    "_id": "2",
    "_score": 0.0,
    "_source": {
    "order_id": 789,
    "product_id": 4321,
    "order_date": "2020-11-01",
    "day of week": "Monday",
    "currency": "USD"
    }
    }
    ]

    关于elasticsearch - 在 Elasticsearch 中从内部查询获取值列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63441542/

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