Elasticsearch过滤器/计数嵌套字段

编程入门 行业动态 更新时间:2024-10-18 03:22:59
本文介绍了Elasticsearch过滤器/计数嵌套字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的文档带有如下所示的嵌套字段:

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过滤器/计数嵌套字段

本文发布于:2023-11-22 05:52:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616212.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   字段   过滤器   Elasticsearch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!