Elasticsearch range query with partly search in it


(trusha) #1

I’m having one database with consist of car tracking information in it. I’m importing all the records to Elasticsearch through Bulk API. While working on Range queries for “Datetime” field (eg: 2014-06-08T00:07:28.000 ), for which I’m giving mapping type as “date” and format as “strict_date_hour_minute_second_millis”. For such scenario, I want to search only with time constraint (T00:07:28.000/00:07:28.000) of my “Datetime” field say for all week days I want to compute traffic between 3pm to 4pm. So with range query, I’m not able to give just time constraint of Datetime field because it gives me errors that format is invalid. Is there any solution for this problem domain with any other query type?
Bulk records (sample):
{"index":{"_id": "178790318"}}
{"Id":"178790318","Description":"Kynoch Rd, Durban City, Durban, KwaZulu-Natal, South Africa","Odometer":"578676","Ignition":"ON","Location":{"lat":"-30.0178","lon":"30.9065"},"Reg":"ND343265","Speed":"9","Datetime":"2014-06-08T00:07:29.000"}
{"index":{"_id": "178790319"}}
{"Id":"178790319","Description":"Lyndhurst Rd, John Dube Village, East London, Eastern Cape, South Africa","Odometer":"367210","Ignition":"ON","Location":{"lat":"-33.0003","lon":"27.8418"},"Reg":"TEMP-CT959623","Speed":"19","Datetime":"2014-06-08T00:07:29.000"}
Mapping:
{
"mappings": {
"cartrack": {

        "properties": {
            "Id": {"type": "Long"},
            "Description": {"type": "string"},
            "Odometer":{"type":"Long"},
            "Ignition":{"type":"String"},
            "Location": {"type": "geo_point"},
            "Reg": {"type": "string"},
            "Speed": {"type": "Long"},
            "Time": {
                "type":   "date",
                "format":"strict_date_hour_minute_second_millis"                   
            }
        }
    }
}

}

Search query:
{
"query": {
"bool": {
"must": [
{
"match":{
"Ignition": "OFF"
}
},
{
"range": {
"Time": {
"from":"00:07:28.000" ,
"to":"00:07:29.000"
}
}
}
]
}
},
"aggs": {
"No_of_vehicles": {
"cardinality": {
"field": "Reg"
}
}
}
}


(system) #2