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,
|ID|Product|Price|City|State|
|100|ABC|$201|Seattle|WA|
|101|XUY|$423|Seattle|WA|
|102|DEF|$252|Atlanta|GA|
|103|GEY|$325|Chicago|IL|
|104|BDV|$263|Atlanta|GA|

and what I expect finally is:
|City|State|
|Seattle|WA|
|Atlanta|GA|
|Chicago|IL|

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.