How do I get parts of a document distinctly

I tried to simulate my date with the following table. But what I want out of it is three records containing City & State.
e.g. Lets original data will look like,

and what I expect finally is:

Could you please help me get a query or suggest something?
I used a table instead of JSON for display pupose
Thank you.

Source filtering allows you to define which fields of each document should be returned.

Yeah but here I think he wants to group by some terms.
So I'd recommend looking at terms aggregation.

1 Like

Thank you guys,

"_source": is only limiting the result to the fields i want to return.
and applying aggs like this:
"aggs" : {
"by_city": {
"terms": {
"field": "city.keyword"

doesn't update the hits but it returns separate buckets for each aggregate. Am I doing something wrong? The ultimate goal is I want the distinct records that I could eventually paginate over.

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