我的文档带有如下所示的嵌套字段:
I have documents with a nested field that looks like this:
... "results": [ { "id": "1234", "name": "asdf" }, { "id": "5678", "name": "jklö" } ], "ip": "1.2.3.4" ...嵌套字段的映射如下:
"results": { "type": "nested", "properties": { "id": { "type": "string" }, "name": { "type": "string" } } }在我切换到Elasticsearch 2之前,我有一个带有aggs的查询,该查询计算了没有结果的文档。这是查询的汇总部分:
Before I switched to elasticsearch 2 I had a query with aggs that counted the documents that had no results. Here's the aggregation part of the query:
"aggs": { "no_result": { "filter": { "missing": { "field": "results" } }, "aggs": { "count": { "value_count": { "field": "ip" } } } } }现在我切换到elasticserach 2,它只计算所有文档。我已经尝试过其他方法,例如计算所有文档和计算结果,以便可以减去结果,但是
Now that I switched to elasticserach 2 it just counts all documents. I already tried different things like counting all documents and counting results so that I can subtract the results but
"aggs": { "results_count": { "value_count": { "field": "results" } } }总是0
如何正确过滤/计数嵌套字段?
How can I correctly filter/count my nested fields?
推荐答案如果您要计算具有结果的文档数,则可以执行此操作。
if you want to count the number of documents which have results you can do this.
{ "size": 0, "aggs": { "count": { "nested": { "path": "results" }, "aggs": { "top_reverse_nested": { "reverse_nested": {} } } } } }数字计数将在top_reserve_nested doc_count
the number count will be in top_reserve_nested doc_count
更多推荐
Elasticsearch过滤器/计数嵌套字段
发布评论