Nested Aggregation (Group by cluase)

Hi All,

I am pretty new to elasticsearch, my project requires me to write a
group-by clause query.
I am trying to write a nested dsl using aggregation which will be like a
group by clause.

Structure of Input Document is something like this:

{
"_source": {
"id": 1234,
"oid": 6,

           "education": [
              {
                 "school_name": "Harvard",
                 "city" : "Boston",
                 "year": 1965,
                 "degree": "Undergrad"
              },
              {
                 "school_name": "Harvard",
                 "city" : "Boston",
                 "year": 1975,
                 "degree": "Masters"
              },
              {
                 "school_name": "Harvard",
                 "city" : "Boston",
                 "year": 1958,
                 "degree": "BA"
              }  
           ],
        }
     },

----Another records... and so on

*Above shown document complies to one record.

Goal: I am trying to find out all those students who studied in Boston.
So Ideally if I have only above document then I should get only 1 record.

With the nested aggregation query I have written below I am getting 3 as a
count for Boston

GET cluster_test/index_test/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"oid": {
"value": "6"
}
}
}
]
}
},
"aggs": {
"education": {
"nested": {
"path": "education"
},
"aggs": {
"edu": {
"terms": {
"field": "education.city",
"size": 0
}
}
}
}
}
}

If anyone can point out where I am going wrong or what is better to deal
with these type of queries.
Any help is appreciated.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/4dc2ccc6-114e-4594-8a49-b19d4c41742f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

1 Like