Reputation: 23
How to get all the unique documents from a index.Do i need to write the aggregation queries for all the fields of document. Can i get unique documents without writting the aggregation for each n every field.
Upvotes: 0
Views: 424
Reputation: 1167
you can do that with script :
PUT test/doc/1
{ "field1": "value1", "field2": "value2" }
PUT test/doc/2 { "field1": "value2", "field2": "value3" }
PUT test/doc/3 { "field1": "value1", "field2": "value3" } PUT test/doc/4 { "field1": "value3", "field2": "value4" }
GET test/_search { "size": 0, "aggs": { "cardinality": { "cardinality": { "script": { "inline": "[ doc['field1'].value, doc['field2'].value ]" } } } } }
From discuss elastic
Upvotes: 0