How to get the values โ€‹โ€‹of repeating fields in elastic search by the field name without knowing its value

I have the "EmployeeName" field in the elastic search index - and I would like to execute a query that will return to me all cases when there are duplicate "EmployeeName" values. It can be done?

I found more_like_this, but this requires a field value for "like_text". But my requirement is to get a list of employees who have duplicate names, not knowing its meaning.

{ "more_like_this" : { "fields" : ["EmployeeName"], "like_text" : "Mukesh", "min_term_freq" : 1, "max_query_terms" : 12 } } 

Thanks at Advance

Relations Mukesh

+5
source share
2 answers

You can use Terms Aggregation for this.

 POST <index>/<type>/_search?search_type=count { "aggs": { "duplicateNames": { "terms": { "field": "EmployeeName", "size": 0, "min_doc_count": 2 } } } } 

This will return all values โ€‹โ€‹of the EmployeeName field that appear in at least two documents.

+10
source

This will be a request with the current version of Elasticsearch:

 GET <index>/_search { "size": 0, "aggs": { "duplicateNames": { "terms": { "field": "EmployeeName", "min_doc_count": 2 } } } } 
0
source

All Articles