ElasticSearch Aggregation over Top Hits

后端 未结 2 1684
我在风中等你
我在风中等你 2021-01-17 20:47

I have data as following:

{\"action\":\"CREATE\",\"docs\":1,\"date\":\"2016 Jun 26 12:00:12\",\"userid\":\"1234\"}
{\"action\":\"REPLACE\",\"docs\":2,\"date\         


        
2条回答
  •  有刺的猬
    2021-01-17 21:19

    You can have other aggregation on a parallel level of top_hit but you cannot have any sub_aggregation below top_hit. It is not supported by elasticsearch. here is the link to github issue

    But if you want to have sum at the same level, you may use the approach below.

    "aggs": {
        "top_hits_agg": {
            "top_hits": {
                "size": 10,
                "_source": {
                  "includes": ["docs"]
                }
            }
        },
        "sum_agg": {
            "sum": {
                "field": "docs"
            }
        }
    }
    

提交回复
热议问题