Unique return like GROUP BY


(Stephan Daratha) #1

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?


#2

You could use field collapsing and collapse on field uniqueKey

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


(Stephan Daratha) #3

That is perfect. Thank you for your advice


(system) #4

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