user2896120
user2896120

Reputation: 3282

Aggregating data based on string value

I have thousands of documents in my index and what I'm trying to do is aggregate documents with the same date and display how many there are with that date. The dates are in strings. To give you a better picture of what I want, say the field for the date is called arrivalDate and each document has a specific arrivalDate. I want the data to be displayed something like this:

20110105 : 5 records

20120501 : 2 records

20120602 : 15 records

and so forth. This is basically like a GROUP BY SQL query except using elastic search. How do I build such a query using elastic search?

Upvotes: 0

Views: 30

Answers (1)

Darth Kotik
Darth Kotik

Reputation: 2361

What you need is term aggregation. It will look something like this.

{
  "aggs": {
    "group_bu_date": {
      "terms": {
        "field": "arrivalDate"
      }
    }
  }
}

Upvotes: 3

Related Questions