gpt4 book ai didi

python - 在 Elasticsearch 中分组并过滤两个日期之间的max(date)

转载 作者:行者123 更新时间:2023-12-03 00:13:14 25 4
gpt4 key购买 nike

目前,我们可以在 flex 搜索中按customer_id分组。

以下是文档结构

{
"order_id":"6",
"customer_id":"1",
"customer_name":"shailendra",
"mailing_addres":"shailendra@gmail.com",
"actual_order_date":"2000-04-30",
"is_veg":"0",
"total_amount":"2499",
"store_id":"276",
"city_id":"12",
"payment_mode":"cod",
"is_elite":"0",
"product":["1","2"],
"coupon_id":"",
"client_source":"1",
"vendor_id":"",
"vendor_name: "",
"brand_id":"",
"third_party_source":""

}

现在我们需要过滤组以查找文档
  • 两个日期之间的最后排序日期
  • 两个日期之间的一阶日期

  • 我们怎样才能做到这一点?

    最佳答案

    您可以尝试以下查询。在每个客户群中,我们进一步过滤两个日期之间的所有文档(此处我取的是2016年8月),然后在date字段上运行stats聚合。 min值将是第一个订购日期,而max值将是最后订购日期。

    {
    "aggs": {
    "customer_ids": {
    "terms": {
    "field": "customer_id"
    },
    "aggs": {
    "date_filter": {
    "filter": {
    "range": {
    "actual_order_date": {
    "gt": "2016-08-01T00:00:00.000Z",
    "lt": "2016-09-01T00:00:00.000Z"
    }
    }
    },
    "aggs": {
    "min_max": {
    "stats": {
    "field": "actual_order_date"
    }
    }
    }
    }
    }
    }
    }
    }

    关于python - 在 Elasticsearch 中分组并过滤两个日期之间的max(date),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38976025/

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