Get unique of date in data


(Ankur Singla) #1

I am having data with date field value in "dd-mm-yyyy" format in my index. I try to find the unique of date with cardinality aggregation but i am getting wrong result.

POST /index/_search?size=-0
{
    "aggs" : {
        "type_count" : {
            "cardinality" : {
                "field" : "dateField"
            }
        }
    }
} 

My data has around 200 date unique dates but it is returning 3. Does cardinality aggregation works on date property?


(Adrien Grand) #2

Can you share the output of the terms aggregation on the same field?


(Ankur Singla) #3

Here is the output-
{
"took": 1031,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 17622001,
"max_score": 0,
"hits": []
},
"aggregations": {
"type_count": {
"value": 3
}
}
}


(Adrien Grand) #4

Sorry, I meant a terms aggregation: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html but it seems you ran something else?


(Ankur Singla) #5

I ran

GET /order/_search
{
    "aggs" : {
        "genres" : {
            "terms" : { "field" : "creationDateOnlyStr" }
        }
    }
}

& it returns -

"aggregations": {
    "genres": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": 1483229280000,
          "key_as_string": "01-08-2017",
          "doc_count": 6450000
        },
        {
          "key": 1483228860000,
          "key_as_string": "01-01-2017",
          "doc_count": 5832001
        },
        {
          "key": 1483229040000,
          "key_as_string": "01-04-2017",
          "doc_count": 5340000
        }
      ]
    }
  }

Still not expected result


(Adrien Grand) #6

Thanks, I think I understand the problem: you used dd-mm-yyyy instead of dd-MM-YYYY. For y it doesn't matter, but for m it does since m is minute of hour while M is month of the year: http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html.


(Ankur Singla) #7

It works...

Thanks!!!!:grinning:


(system) #8

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