# How to use "nested" properties fields in query script

**URL:** <https://discuss.elastic.co/t/how-to-use-nested-properties-fields-in-query-script/214621>\
**Category:** Elasticsearch\
**Created:** [January 10, 2020, 3:23pm UTC](https://discuss.elastic.co/t/how-to-use-nested-properties-fields-in-query-script/214621 "2020-01-10T15:23:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![astfgl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/astfgl/32/60612_2.png) [@astfgl](https://discuss.elastic.co/u/astfgl)\
**Post date:** [January 10, 2020, 3:23pm UTC](https://discuss.elastic.co/t/how-to-use-nested-properties-fields-in-query-script/214621/1 "2020-01-10T15:23:55Z")

</div>

Hi,  
I'm using Elasticsearch v6.5.0.

my sample data:

```auto
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:

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

```

I have following mapping config:

```auto
    "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](https://gist.github.com/jan-kran/0cca0e779b4ee826cd7485008cb68eb7#file-create_index-json)

More sample data [here](https://gist.github.com/jan-kran/0cca0e779b4ee826cd7485008cb68eb7#file-insert_data-json)

I can query this field:

```auto
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:

```auto
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:

```auto
{
  "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:

```auto
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

---

<div class="post-metadata">

**Author:** ![astfgl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/astfgl/32/60612_2.png) [@astfgl](https://discuss.elastic.co/u/astfgl)\
**Post date:** [January 13, 2020, 9:23am UTC](https://discuss.elastic.co/t/how-to-use-nested-properties-fields-in-query-script/214621/2 "2020-01-13T09:23:59Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 10, 2020, 9:24am UTC](https://discuss.elastic.co/t/how-to-use-nested-properties-fields-in-query-script/214621/3 "2020-02-10T09:24:08Z")

</div>

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