Home > Enterprise >  elasticsearch count number of data in every month
elasticsearch count number of data in every month

Time:07-28

I have a *.csv file like this.

id,create_date,data
60,2019/6/12 16:19,A
2,2019/6/12 16:45,A
3,2019/6/13 10:53,A
4,2019/6/20 16:22,A
5,2019/6/26 18:49,B
6,2019/7/8 16:48,B
7,2019/7/8 16:48,B
8,2019/7/8 16:49,A
9,2019/7/8 16:49,B
77,2019/7/8 16:50,B
11,2019/7/8 16:52,B
12,2019/7/8 16:52,B
13,2019/7/8 16:53,B
14,2019/7/8 16:56,B
15,2019/7/8 16:57,B
16,2019/7/8 16:58,B
17,2019/7/8 17:00,B
18,2019/7/9 13:11,B
19,2019/8/12 10:38,B
20,2019/8/12 10:43,B
21,2019/8/12 10:46,B
65,2019/8/12 10:54,B
23,2019/8/12 10:57,B
87,2019/8/1 11:31,B
25,2019/8/5 11:58,B
104,2019/8/14 12:35,B
112,2019/8/17 14:19,B
106,2019/8/17 14:21,B

And I've imported it to my elasticsearch as an index using "Upload a file" integration.

enter image description here

How can I use enter image description here

And set the format of your date like so:

enter image description here

Then you will ba able to perform date aggregation.

Solution

GET /73135106/_search
{
  "size": 0,
  "aggs": {
    "per_month": {
      "date_histogram": {
        "field": "@timestamp",
        "calendar_interval": "month"
      },
      "aggs": {
        "num_doc": {
          "terms": {
            "field": "data",
            "size": 10
          }
        }
      }
    }
  }
}
  • Related