# Nested field size script

**URL:** <https://discuss.elastic.co/t/nested-field-size-script/276013>\
**Category:** Elasticsearch\
**Created:** [June 15, 2021, 2:06pm UTC](https://discuss.elastic.co/t/nested-field-size-script/276013 "2021-06-15T14:06:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tfe2012](https://avatars.discourse-cdn.com/v4/letter/t/49beb7/32.png) [@tfe2012](https://discuss.elastic.co/u/tfe2012)\
**Post date:** [June 15, 2021, 2:06pm UTC](https://discuss.elastic.co/t/nested-field-size-script/276013/1 "2021-06-15T14:06:35Z")

</div>

Hi, I try to get all documents which nested field size \> 1

my mapping:

```auto
"selectStatsListNested" : {
          "type" : "nested",
          "properties" : {
            "isSampleSelect" : {
              "type" : "boolean"
            },
            "movedAt" : {
              "type" : "date"
            },
            "searchId" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "selectedAt" : {
              "type" : "date"
            },
            "userId" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        }

```

My query:

```auto
GET people/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "selectStatsListNested",
            "query": {
                "script": {
                    "script": """
                      if (doc.containsKey('selectStatsListNested.userId')) {
                        if (doc['selectStatsListNested'].values.size() > 1) {
                          return true;
                        }
                      }
                      return false;
                    """
                }
            }
        }
        }
      ]
        
    }
}
, "_source": "selectStatsListNested"
}

```

But getting this error:

```auto
"error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "runtime error",
        "script_stack" : [
          "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:88)",
          "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:40)",
          "if (doc['selectStatsListNested'].values.size() > 1) {\n ",
          " ^---- HERE"
        ]

```

Can you help what I'm doing wrong :)?

---

<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:** [July 13, 2021, 2:07pm UTC](https://discuss.elastic.co/t/nested-field-size-script/276013/2 "2021-07-13T14:07:24Z")

</div>

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