gpt4 book ai didi

elasticsearch - 在ElasticSearch中通过父值过滤子项

转载 作者:行者123 更新时间:2023-12-03 02:01:27 25 4
gpt4 key购买 nike

我有一个包含三种文档类型的索引:

  • 潜在客户-具有以及ID和类型(帐户的子级)
  • 帐户-具有ID
  • 付款-具有和ID,类型和account_id(帐户的子代)

  • 他们都是亲子关系。
    我想获取有关我有哪些潜在顾客类型的统计信息(按类型分组),然后计算我有多少这种特定类型的付款。

    我来到此查询,但我无法按父类型过滤子聚合。
    查询 Lead类型
    {
    "query": {
    "match_all": {}
    },
    "aggs": {
    "by_type": {
    "terms": {
    "field": "type"
    },
    "aggs": {
    "payments_count": {
    "filter": {
    "and": [
    {
    "has_parent": {
    "type": "account",
    "query": {
    "filtered": {
    "query": {
    "match_all": {}
    },
    "filter": {
    "and": [
    {
    "has_child": {
    "type": "payment",
    "query": {
    "filtered": {
    "query": {
    "match_all": {}
    },
    "filter": {
    "and": [
    {
    "term": {
    "type": ?????????
    }
    }
    ]
    }
    }
    }
    }
    }
    ]
    }
    }
    }
    }
    }
    ]
    }
    }
    }
    }
    }
    }

    在上一个has_child过滤器中,我想知道如何通过父项的 lead.type过滤子项,如下所示:
    "filter": {
    "and": [
    {
    "term": {
    "type": "$lead.type"
    }
    }
    ]
    }

    另外,由于另一种关于 lead类型的聚合,我无法逆转此查询。

    任何帮助将非常感激

    最佳答案

    您正在针对类型“lead”运行查询,因此,如果要对“lead.type”进行过滤,则应在进入其父级之前将其作为第一个过滤器聚合进行。

    "payments_count": {
    "filter": {
    "and": [
    {
    "term": {
    "type": "$lead.type"
    }
    },
    {
    "has_parent": {
    ...

    也许我的查询也有所帮助,因为它有点类似: Term Filter on a nested field called id does not work as expected

    关于elasticsearch - 在ElasticSearch中通过父值过滤子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32097916/

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