How to use "nested" properties fields in query script

Hi,
I'm using Elasticsearch v6.5.0.

my sample data:

PUT index/pim_catalog_product/bbb_2255444
{
  "id": "2838",
  "identifier": "bbb_2255444",
  "created": "2019-12-05T11:34:36+00:00",
  "values": {
    "footwear_size-option": {
      "<all_channels>": {
        "<all_locales>": "42"
      }
    },
    "description_created-date": {
      "<all_channels>": {
        "<all_locales>": "2019-12-19"
      }
    }
  }
}

I would like to use field description_created-date in query script to perform a query like this:

SELECT * FROM table
 WHERE `description_created-date` > DATE_ADD(`created`, INTERVAL 2 DAY);

I have following mapping config:

    "properties": {
      "created": {
        "type": "date"
      },
      "id": {
        "type": "keyword"
      },
      "identifier": {
        "type": "keyword"
      },
      "properties": {
        "values": {
          "properties": {
            "description_created-date": {
              "properties": {
                "<all_channels>": {
                  "properties": {
                    "<all_locales>": {
                      "type": "date"
                    }
                  }
                }
              }
            },
            "footwear_size-option": {
              "properties": {
                "<all_channels>": {
                  "properties": {
                    "<all_locales>": {
                      "type": "keyword"
                    }
                  }
                }
              }
            }
          }
        }
      }

Full create request is on this gist

More sample data here

I can query this field:

GET index/pim_catalog_product/_search
{
  "query": {
    "match": {
      "values.description_created-date.<all_channels>.<all_locales>": "2019-12-19"
    }
  }
}

But I don't know how to use it in query script:

GET index/pim_catalog_product/_search
{
  "query": {
    "constant_score": {
      "filter": {
        "bool": {
          "filter": [
            {
              "script": {
                "script": {
                  "source": "doc['values']['description_created-date']['<all_channels>']['<all_locales>'].value == '2019-12-19'",
                  "lang": "painless"
                }
              }
            }
          ]
        }
      }
    }
  }
}

gives following error:

{
  "shard": 0,
  "index": "index",
  "node": "cmh1RMS1SHO92SA3jPAkJA",
  "reason": {
    "type": "script_exception",
    "reason": "runtime error",
    "script_stack": [
      "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:81)",
      "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:39)",
      "doc['values']['description_created-date']['<all_channels>']['<all_locales>'].value == '2019-12-19'",
      "    ^---- HERE"
    ],
    "script": "doc['values']['description_created-date']['<all_channels>']['<all_locales>'].value == '2019-12-19'",
    "lang": "painless",
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "No field found for [values] in mapping with types [pim_catalog_product]"
    }
  }
}

Is there a way to use this filed in script query? If so - how can I do that?

I know version 6.5.0 is not the newest one, but this is what we have. So if you wish to help me, here is simple docker-compose file to run this version along with kibana:

version: '3'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.5.0
    environment:
      - discovery.type=single-node
    ports:
      - 9200:9200
  kibana:
    image: docker.elastic.co/kibana/kibana:6.5.0
    ports:
      - 5601:5601

Thank you!
Jan

For future reference: I was able to access this field using dot notation:

doc['values.description_created-date.<all_channels>.<all_locales>'].value

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