0

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.

Akib Ali
  • 23
  • 1
  • 7

1 Answers1

0

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

Lax
  • 1,109
  • 1
  • 8
  • 13