Query with Date filter


(Robert Naccache) #1

Hello,

I'm trying to return documents for the month of December that have a time stamp between 8AM to 4PM of every day.

I currently have a timestamp field which is a date/time field (in the form 2017-12-17T22:00:00.355Z)

My query looks like this

GET as400-*/_validate/query?rewrite=true
{
"query":{
"bool": {
"must": [
{"match": {"monitoringtable": "GYPF"}},
{"range": {
"timestamp": {
"gte": "08:00:00",
"lte": "16:00:00"
, "format": "HH:mm:ss"
}
}}
]
}
}
}

but when i run the query, i don't get any results.

"valid": true,
"explanation": """MatchNoDocsQuery("User requested "match_none" query.")"""

Is this sort of query possible in elastic?

Thank you for your time.


(David Pilato) #2

That's hard if you did not index the hour of the day as a separate value like:

{
  "date": "2017-12-17T22:00:00.355Z",
  "hour": 22
}

In that case you need I believe to execute a script Query. See https://www.elastic.co/guide/en/elasticsearch/reference/6.1/query-dsl-script-query.html. But that is going to be slow. If it's something you want to do often, I'd index another field.

HTH


(Robert Naccache) #3

Hi David,

Thanks for taking the time to reply.

I think going with indexing the hour separately sounds better as i'm importing the data using logstash.

Just making sure elasticsearch couldn't somehow extract the value before taking this approach.

Thanks again, have a good day!


(system) #4

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