Weird issue with date sort


(Nicolas F) #1

Hi,

I have an issue with date field.

With this queries:

DELETE ds3

PUT ds3
{
   "mappings":{
      "ds2":{
         "properties":{
            "producerID":{
               "type":"keyword"
            },
            "timestamp":{
               "type":"date"
            },
            "c1":{
               "type":"double"
            },
            "c2":{
               "type":"integer"
            },
            "c3":{
               "type":"text"
            }
         }
      }
   }
}

POST ds3/ds2/ds2%23%230%23%23urn%3Adomain%3Asensors%3A1
{
   "producerID":"urn:domain:sensors:1",
   "timestamp":0,
   "c1":0.3,
   "c2":0,
   "c3":"test0"
}

POST ds3/ds2/ds2%23%4607182418800017408%23%23urn%3Adomain%3Asensors%3A1
{
   "producerID":"urn:domain:sensors:1",
   "timestamp":1000,
   "c1":10.3,
   "c2":20,
   "c3":"test10"
}

POST ds3/ds2/_search
{

   "size": 1,
    "sort" : [
        { "timestamp" : {"order" : "asc"}}
    ]
}


I expect the sort of the values done on timestamp to return the timestamp 0. But it return the timestamp 1000.

I'm using ElasticSearch 6.3.0

Do you know why ?

Thanks


(David Pilato) #2

I don't know TBH. Could you try with more recent timestamps to see if this reproduces?


(Nicolas F) #3

The issue is that it won't work with timestamps < 1000

I have to fix this because I must follow some generic unit test for storage system that use time stamps from 0 to 10000


(David Pilato) #4

Why not using a number instead of a date then?


(Nicolas F) #5

Yes this is a workaround.

Is that a bug of ElasticSearch or not ?


(David Pilato) #6

Might be. I think @jpountz already answered such a question in the past but I don't recall exactly. Adrien, could you confirm if this is an "expected bug"? :slight_smile:


(Nicolas F) #7

Hi,

For the record,

Solved by specifying the time format to epoch_millis (in both mapping and in query)

Then epoch_millis must be in the following millisecond bounds:

private static final long MIN_DATE_EPOCH = -62138538000000L;
private static final long MAX_DATE_EPOCH = 253336460400000L;

Thanks

Regards,


(system) #8

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