Unique return like GROUP BY

Hi there,

I thought it would be easy. But I failed.

We have an index with objects like

{'objectNumber: '123', 'persons':4, 'uniqueKey': 'abc'}
{'objectNumber: '456', 'persons':2, 'uniqueKey': 'def'}
{'objectNumber: '789', 'persons':6, 'uniqueKey': 'abc'}

My problem is that if I query objects where persons gte: 4 I will get 2 results.
Is it possible that I only get one object per uniqueKey?

If I change the query to gte: 2 persons I want 2 hits.

How is that possible?

You could use field collapsing and collapse on field uniqueKey

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-collapse.html

1 Like

That is perfect. Thank you for your advice

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