简体   繁体   English

获取ElasticSearch中日期直方图上缺少字段的文档计数?

[英]Get count of documents missing a field over a date histogram in ElasticSearch?

I'm trying to find out the number of documents that don't contain a certain field grouped daily. 我正在尝试找出不包含每天分组的某个字段的文档数量。

The idea being that I can work out the daily response rate statistic. 我的想法是可以计算出每日响应率统计信息。

I'm using PHP but can happily convert a JSON query to a suitable nested array. 我正在使用PHP,但可以将JSON查询愉快地转换为合适的嵌套数组。

Here's what I have so far. 到目前为止,这就是我所拥有的。

$params['aggs'] = [
                "daily"=> [
                    "date_histogram"=> [
                        "field" => "date_created",
                        "interval" => "1d",
                        "min_doc_count" => 0
                    ],
                    "aggs"=>[
                        "unresponded"=>[
                            "missing"=>[
                                "field"=> "responses"
                            ]
                        ]
                    ]
                ]
            ];

This returns data, with an unresponded bucket for each daily bucket as expected, however the values don't tally up with the data. 这会返回数据,并且按预期每个daily存储桶都unresponded ,但是这些值与数据不符。 Instead every document that is in the daily bucket is accounted for in the unresponded bucket regardless of whether documents from that particular day have a response field or not. 取而代之的是, daily存储桶中的每个文档都将在未unresponded存储桶中进行处理,而不管该特定日期的文档是否具有response字段。

Looks like the missing aggregation doesn't work for existing but empty array fields. 看起来missing聚合不适用于现有但空的数组字段。 I had to rework the aggregation to make use of a boolean must-not exist. 我不得不对聚合进行重新处理,以使用布尔型必须存在的布尔值。

"aggs"=>[
    "responded"=>[
          "filter"=>[
               "query"=>[
                   "bool"=>[
                       "must_not"=>[
                           "exists"=>[
                               "field"=>"responses"
                            ]
                        ]
                    ]
                ]
           ]
      ]
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM