Skip to content

Instantly share code, notes, and snippets.

@imotov
Created December 15, 2013 21:12
Show Gist options
  • Save imotov/7978186 to your computer and use it in GitHub Desktop.
Save imotov/7978186 to your computer and use it in GitHub Desktop.
Inconsistent treatment of dates without year
curl -XDELETE "localhost:9200/test-idx?pretty"
curl -XPUT "localhost:9200/test-idx?pretty" -d '{
"settings": {
"number_of_replicas": 0,
"number_of_shards": 1
},
"mappings": {
"doc": {
"properties": {
"event_time" : {
"type" : "date",
"format" : "MMM dd HH:mm:ss"
}
}
}
}
}'
curl -XPUT "localhost:9200/test-idx/doc/1?pretty" -d '{"event_time":"Dec 15 14:44:24"}'
curl -XPUT "localhost:9200/test-idx/doc/2?pretty" -d '{"event_time":"Dec 15 14:44:24"}'
curl -XPOST "localhost:9200/test-idx/_refresh?pretty"
echo "========================================================================"
echo "In sort values are based on Jan 1 2000"
curl -s -XGET 127.0.0.1:9200/test-idx/doc/_search?pretty=true -d '{
"sort": [
{
"event_time": {
"order": "desc"
}
}
]
}'
echo "========================================================================"
echo "In search values are based on Jan 1 2000 for lower bound and upper bound when it's excluded"
curl -s -XGET "127.0.0.1:9200/test-idx/doc/_validate/query?pretty=true&explain=true" -d '{
"range": {
"event_time": {
"lt": "Dec 15 15:00:00",
"gt": "Dec 15 16:00:00"
}
}
}'
echo "========================================================================"
echo "But it based on Jan 1 1970 for upper bound if upper bound is included"
curl -s -XGET "127.0.0.1:9200/test-idx/doc/_validate/query?pretty=true&explain=true" -d '{
"range": {
"event_time": {
"lte": "Dec 15 15:00:00",
"gte": "Dec 15 16:00:00"
}
}
}'
{
"ok" : true,
"acknowledged" : true
}
{
"ok" : true,
"acknowledged" : true
}
{
"ok" : true,
"_index" : "test-idx",
"_type" : "doc",
"_id" : "1",
"_version" : 1
}
{
"ok" : true,
"_index" : "test-idx",
"_type" : "doc",
"_id" : "2",
"_version" : 1
}
{
"ok" : true,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
}
}
========================================================================
In sort values are based on Jan 1 2000
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : null,
"hits" : [ {
"_index" : "test-idx",
"_type" : "doc",
"_id" : "1",
"_score" : null, "_source" : {"event_time":"Dec 15 14:44:24"},
"sort" : [ 976891464000 ]
}, {
"_index" : "test-idx",
"_type" : "doc",
"_id" : "2",
"_score" : null, "_source" : {"event_time":"Dec 15 14:44:24"},
"sort" : [ 976891464000 ]
} ]
}
}
========================================================================
In search values are based on Jan 1 2000 for lower bound and upper bound when it's excluded
{
"valid" : true,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"explanations" : [ {
"index" : "test-idx",
"valid" : true,
"explanation" : "event_time:{976896000000 TO 976892400000}"
} ]
}
========================================================================
But it based on Jan 1 1970 for upper bound if upper bound is included
{
"valid" : true,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"explanations" : [ {
"index" : "test-idx",
"valid" : true,
"explanation" : "event_time:[976896000000 TO 30121200999]"
} ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment