ElasticSearch聚合布尔过滤器查询

时间:2020-01-08 19:50:30

标签: elasticsearch

当我跑步时:

query: {
    bool: {
        filter: [
            { term: { "data.ID": "12345" } },
            { range: { "@timestamp": {"gte": "now-3M"} } },
        ],
    },
}

我得到这样的结果(为简单起见,我删除了额外的数据):

[
    {
        Data: {
            ID: "12345",
            type: "invoice"
        },
        Meta: {
            DateTime: "2020-01-07T21:00:24.738"
        }
    },
    {
        Data: {
            ID: "12345",
            type: "invoice"
        },
        Meta: {
            DateTime: "2020-01-07T21:00:25.245"
        }
    },
    {
        Data: {
            ID: "12345",
            type: "self"
        },
        Meta: {
            DateTime: "2020-01-07T21:00:25.245"
        }
    }
]

如果发票结果相距3秒之内,我希望能够汇总它们。

我的尝试如下:

query: {
    bool: {
        filter: [
            { term: { "data.ID": "12345" } },
            { range: { "@timestamp": {"gte": "now-3M"} } },
            aggs: {
                my_agg: {
                    "date_histogram": { 
                        "field": "@timestamp",
                        "interval": "3s"
                    },
                    { term: { "data.type": "invoice" } }
                }
            },
        ],
    },
}

我希望它返回如下内容:

[
    [
        {
            Data: {
                ID: "12345",
                type: "invoice"
            },
            Meta: {
                DateTime: "2020-01-07T21:00:24.738"
            }
        },
        {
            Data: {
                ID: "12345",
                type: "invoice"
            },
            Meta: {
                DateTime: "2020-01-07T21:00:25.245"
            }
        }
    ],
    {
        Data: {
            ID: "12345",
            type: "self"
        },
        Meta: {
            DateTime: "2020-01-07T21:00:25.245"
        }
    }
]

但是它返回[parsing_exception] [bool] query does not support [aggs]

我尝试了许多不同的查询,到目前为止,我一直遇到不同的错误。有谁知道该怎么做?

0 个答案:

没有答案