Unable to loop through array field ES 6.1

Hey guys,

I'm facing a problem in ElasticSearch 6.1 that I cannot solve and I don't know why. I have read the docs several times and maybe I'm missing something.

I have a scripted query that needs to do some calculation before decides if a record is available or not.

Here is the following script:

What I'm doing is trying to loop though an array field with the following source:

  "unavailability": [
    {
      "starts_at": "2018-11-27T18:00:00+00:00",
      "local_ends_at": "2018-11-27T15:04:00",
      "local_starts_at": "2018-11-27T13:00:00",
      "ends_at": "2018-11-27T20:04:00+00:00"
    },
    {
      "starts_at": "2018-12-04T18:00:00+00:00",
      "local_ends_at": "2018-12-04T15:04:00",
      "local_starts_at": "2018-12-04T13:00:00",
      "ends_at": "2018-12-04T20:04:00+00:00"
    },
  ]

When the script is executed it throws the error: No field found for [unavailability] in mapping with types [aircraft]

Is there any clue to make it work?

Thanks

UPDATE
Here is the query:

Mapping:

Data example:

I didn't see this was cross-posted, but here's my take:

Hi @val

Thanks for the fast response.

As I previously answered your comment at StackOverflow, I already tried that approach but it throws Variable [_source] is not defined. .

:confused:

See my second comment :wink:

I solve my use-case in a different approach.

Instead having a field as array of object like unavailability was I decided to create two fields as array of datetime:
unavailable_from
unavailable_to

My script walks through the first field then checks the second with the same position.

Hmmm, it might well be this issue that prevents you from getting access to the source field.
Glad you figured another solution.

Oh... sad. :confused:

Thanks for the support and the link @val .

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