Aggregations value formatter - on a multi indices query


(Lior) #1

I'm trying to find the min date on documents of an index.
All works good if i'm trying to do it on a specific index, such as:

GET index1/_search
{
  "size": 0,
  "aggs": {
    "min_date": {
      "min": {
        "field": "date_of_birth"
      }
    }
  }
}

The results is good, and i'm getting the value as string:

"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 545,
"max_score": 0,
"hits": []
},
"aggregations": {
"min_date": {
"value": -155865600000,
"value_as_string": "23/01/1965"
}
}
}

but when i'm adding the search on index2 also, which doesn't have this field:

GET index1,index2/_search
{
  "size": 0,
  "aggs": {
    "min_date": {
      "min": {
        "field": "date_of_birth"
      }
    }
  }
}

The result is in milis only (in the code, i see that the formatter is Raw and not DateTime):
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 10,
"successful": 10,
"failed": 0
},
"hits": {
"total": 1069,
"max_score": 0,
"hits": []
},
"aggregations": {
"min_date": {
"value": -155865600000
}
}
}

Is there a way to solve this?


(Alexander Reelsen) #2

Hey,

is it possible that the date_of_birth field is mapped to a different type in your other index? I just tested with Elasticsearch 5.1.1 and not having such a field in index2 still formatted everything as expected. I might be missing something - can you provide a full reproduction?

--Alex


(Lior) #3

It took my a while, but i think it something to do with the indices names.
I took those mappings:

PUT lala
{
"mappings": {
"type1": {
"properties": {
"date_of_birth": {
"type": "date",
"format": "dd/MM/yyyy"
}
}
}
}
}

PUT index2
{
"mappings": {
"type2": {
"properties": {
"name": {
"type": "string"
}
}
}
}
}

POST lala/type1
{
"date_of_birth" : "07/12/1989"
}

GET lala,index2/_search
{
"size": 0,
"aggs": {
"tata": {
"min": {
"field": "date_of_birth"
}
}
}
}

and the problem occures, but if i change the indices to index1 and index2 so there is no problem...


(system) #4

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