I want to return only terms of a field

By using terms aggregation I am getting terms as well as doct count but i need only terms is there a way to get only terms.

this is the default response

    ...

    "aggregations" : {
        "genres" : {
            "doc_count_error_upper_bound": 0, 
            "sum_other_doc_count": 0, 
            "buckets" : [ 
                {
                    "key" : "jazz",
                    "doc_count" : 10
                },
                {
                    "key" : "rock",
                    "doc_count" : 10
                },
                {
                    "key" : "electronic",
                    "doc_count" : 10
                },
            ]
        }
    }
}

But i need

{
	"aggregations": {
		"genres": {
			"keys": [
				"jazz",
				"rock",
				"electronic"
			]
		}
	}
}

you could use the filter_path parameter - however the numbers would still be calculated though, just omitted in the response. You can however not change the response.

I do not understand how to use filter path to get the required response. Can you please explain?

you could filter on aggregations.genres.buckets.**.key and see if that works to only extract the keys. You cannot modify the JSON though.

Thanks for your reply, now I understand your previous comments also.Can you please tell me is there a way not to calculate the docs_count.

The doc_count is always calculated, unless another metric aggregation is specified.

Hi @spinscale,

thanks for your quick reply can you give an example how to pass another metric.

See https://www.elastic.co/guide/en/elasticsearch/reference/7.4/search-aggregations-metrics.html

There is no java api for filter_path. Isn't it?

you can add it as a parameter, but I would refrain from that using the High Level Rest Client

See https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.4/java-rest-low-usage-requests.html

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.