简体   繁体   中英

ElasticSearch range query isn't returning results within the range

I've really been struggling with getting this to work. Would really appreciate any help with this. Basically I have a time_period field that contain an array of two unix timestamps:

time_period: [1660410000000, 1660842000000]

I'm doing aa range query with two timestamps:

range: {
    time_period: {
        gte: <timestamp>,
        lte: <timestamp>
    }
}

basically I want to get any record where the time_period timestamps overlap in any way with the gte and lte timestamps. It works great EXCEPT for when the gte and lte are WITHIN the time_period range. Then I get nothing.

I figured the default "intersects" relation would work like this, but it doesn't. Any idea what I'm missing or doing wrong?

Thanks in advance for any help!

I would use a date_range field type which is meant for this type of use.

You should map time_period like this:

...
"time_period": {
   "type": "date_range"
}
...

Then your document would contain this:

"time_period": {
    "gte": 1660410000000,
    "lte": 1660842000000
}

And your range query would work out of the box.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM