I am trying to fetch the following section of a document i have indexed through elasticsearch:
temporal: {
begin: "2016-11-30T00:00:00",
end: "2016-12-08T13:55:02"
},
The query that i am using on CURL as i am currently just testing the queries on localhost is the following one :
curl -XGET 'localhost:9201/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query": {
"range" : {
"timestamp" : {
"gte": "2015-01-01 00:00:00",
"lte": "now"
}
}
}
}
'
mapping
temporal: {
properties: {
begin: {
type: "date"
},
end: {
type: "date"
}
}
}
but the above mentioned query does not returns any successful hits although it should return at least the document mentioned above.
Assuming you want to search as you posted ( Note that I've formatted datetime input) , which is timestamp - mapping would be.
{
"temporal" : {
"mappings" : {
"doc" : {
"properties" : {
"temporal" : {
"properties" : {
"begin" : {
"type" : "date",
"format" : "strict_date_optional_time||epoch_millis"
},
"end" : {
"type" : "date",
"format" : "strict_date_optional_time||epoch_millis"
}
}
}
}
}
}
}
}
Indexing / Query document :
curl -XPOST localhost:9200/temporal/doc/1 -d '
{"temporal": {
"begin": "2016-11-30T00:00:00",
"end": "2016-12-08T13:55:02"
}}';
curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query": {
"range" : {
"temporal.begin" : {
"gte": "2015-01-01T00:00:00",
"lte": "now"
}
}
}
}'
{
"took" : 6,
"timed_out" : false,
"_shards" : {
"total" : 108,
"successful" : 108,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "temporal",
"_type" : "doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"temporal" : {
"begin" : "2016-11-30T00:00:00",
"end" : "2016-12-08T13:55:02"
}
}
} ]
}
}