简体   繁体   中英

ElasticSearch - Access array of date_range in painless script filter

Is there any way to access an array of date_range in a painless script filter?

My mapping for the "blocked_dates" field is as follows:

"blocked_dates": {
    "type": "date_range",
    "format": "strict_date"
},

Data looks like this:

"blocked_dates": [
    {
        "gte": "2019-07-12",
        "lte": "2019-07-14"
    },
    {
        "gte": "2019-07-16",
        "lte": "2019-07-18"
    }
],

I am using Amazon ElasticSearch v6.7 so I cannot use params._source in a script filter and if I try and access it via doc then I get an illegal_argument_exception.

"blocked_dates = doc['blocked_dates'].value; ",
"                    ^---- HERE"

Fielddata is not supported on field [blocked_dates] of type [date_range]

I have a complex booking window requirement that checks if the chosen move-in and move-out date is within x days of another booking (blocked date) and this has to be done in a script.

I could do something hacky like store a copy of the array of date_range as a comma delimited (ie "2019-07-20,2019-09-12") string array. Then grab the string array from the painless script filter and parse the dates out of them.

But that is my last resort.

Try params._source.blocked_dates.gte (or lte depends on your needs), but keep in mind what it returned string, but not a date in your particular case.

In my case (float_range) solution was

"script": {
  "lang": "painless",
  "source": "Float.parseFloat(params._source.price.gte)"
}

I think idea is pretty clear

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