3

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.

3
  • 1
    Why these type of questions does not answered by anyone. Facing the same issue and did not find a single answer on internet :( Commented Sep 4, 2019 at 13:17
  • Seems like not a lot of people use Painless scripting Commented Sep 4, 2019 at 23:45
  • @ArcadeRenegade Did you have any progress on that? Commented Jan 1, 2021 at 13:59

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.