Aggregation topHits problem

Hi all!

I need to do aggregation by field and return all relevant hits, not only 10.
But now I have a strange problem: I have 8 relevant hits (according to count), but topHits returns me only 3. Why?

For any further investigation it would be good to know what you are doing. Can you post the aggregation, maybe some sample data, maybe also your mappings if they might play a role in identifying your issue?

Thanks for answer.

In original I have to do aggregation by sevaral fields, but ES doesn't support it.
So, I create not analyzed field which contains json representation of all needed fields and group by it.

Mappings I can't provide, I can provide only code if needed.
I use Java API, ES version is 1.5.2

Just a guess, but by default the top hits aggregation returns 3 hits, so set the size on the top hits builder?

By default it returns 10 records.
If I specify size: MAX_INT, it returns me nothing.

The default for the overall search size is 10, but the default size for top
hits is 3. Two different settings:

https://www.elastic.co/guide/en/elasticsearch/reference/1.5/search-aggregations-metrics-top-hits-aggregation.html#_options_2

This low limit is due to the fact that top hits is not highly performant
and can lead to large responses when larger values are used.

Ivan

Great, thank you.

I have to get two hits from aggregation results, which contains min and max date field respectively.
Can I do this in one terms aggregation using subAggregations? Or I need to do two terms aggregations, in fist I need to get topHit with min date, in second - topHit with max date?