# Script filed

**URL:** <https://discuss.elastic.co/t/script-filed/113793>\
**Category:** Kibana\
**Created:** [January 2, 2018, 2:35pm UTC](https://discuss.elastic.co/t/script-filed/113793 "2018-01-02T14:35:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![radi](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@radi](https://discuss.elastic.co/u/radi)\
**Post date:** [January 2, 2018, 2:35pm UTC](https://discuss.elastic.co/t/script-filed/113793/1 "2018-01-02T14:35:17Z")

</div>

Hello ,  
i want to add script filed to calcul members of "DO" ===\> ( 1 memberId) and "FO" ===\> ( 2 memberId) and return sum --- (3)

i can't get size of doc["model.members"].size() or .length() to make boucle for and sum the result  
I just have access to the filed "model.members.memberId"

"\_index": "Test",

```
   "_type": "pl",
    "_id": "3cd0-0d2f-4e03",
    "_score": 1,
    "_source": {
      "id": "3cd0-0d2f-4e03",
      "model": {
        "name": "FO",
        "members": [
          {
            "memberId": "2173-fdf4",
          },
          {
            "memberId": "d361-21f6",       
          }],

    "_type": "pl",
    "_id": "3cd0-0d2f-4e03",
    "_score": 1,
    "_source": {
      "id": "3cd0-0d2f-4e03",
      "model": {
        "name": "DO",
        "members": [
          {
            "memberId": "4173-fdf4",
          }
       ],
```

---

<div class="post-metadata">

**Author:** ![Joe\_Fleming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_fleming/32/3561_2.png) [@Joe\_Fleming](https://discuss.elastic.co/u/Joe_Fleming)\
**Post date:** [January 2, 2018, 7:33pm UTC](https://discuss.elastic.co/t/script-filed/113793/2 "2018-01-02T19:33:09Z")

</div>

I think it's just `length`, like `doc["model.members"].length`, not `length()` (no parens).

---

<div class="post-metadata">

**Author:** ![radi](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@radi](https://discuss.elastic.co/u/radi)\
**Post date:** [January 3, 2018, 2:38pm UTC](https://discuss.elastic.co/t/script-filed/113793/3 "2018-01-03T14:38:00Z")

</div>

> [@Joe\_Fleming](#):
>
> length

hi, I tested with doc["model.members"].length and i have this messages :

```
"script_stack": [
        "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:77)",
        "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:36)",
        "doc['model.members'].length",
        " ^---- HERE"
      ],
      "script": "doc['model.members'].length",
      "lang": "painless",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "No field found for [model.members] in mapping with types []"
      }

```

---

<div class="post-metadata">

**Author:** ![Joe\_Fleming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_fleming/32/3561_2.png) [@Joe\_Fleming](https://discuss.elastic.co/u/Joe_Fleming)\
**Post date:** [January 3, 2018, 4:16pm UTC](https://discuss.elastic.co/t/script-filed/113793/4 "2018-01-03T16:16:05Z")

</div>

> "No field found for [model.members] in mapping with types "

Are you sure that field exists in the index you're trying to query? Maybe some rows don't have the value? Also, the `types []` in the message is odd, I don't know if that means it is looking at all types, or no types.

---

<div class="post-metadata">

**Author:** ![radi](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@radi](https://discuss.elastic.co/u/radi)\
**Post date:** [January 3, 2018, 4:28pm UTC](https://discuss.elastic.co/t/script-filed/113793/5 "2018-01-03T16:28:13Z")

</div>

With doc['model.members.membersId'].size() in my script i got the count of members

---

<div class="post-metadata">

**Author:** ![Joe\_Fleming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_fleming/32/3561_2.png) [@Joe\_Fleming](https://discuss.elastic.co/u/Joe_Fleming)\
**Post date:** [January 3, 2018, 5:19pm UTC](https://discuss.elastic.co/t/script-filed/113793/6 "2018-01-03T17:19:29Z")

</div>

Interesting, I would have thought what you had before would work, I didn't realize you had to reach into the document too. Thanks for following up, it's helpful for other people searching for answers.

---

<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:** [January 31, 2018, 5:20pm UTC](https://discuss.elastic.co/t/script-filed/113793/7 "2018-01-31T17:20:10Z")

</div>

Closed on January 31, 2018, 5:20pm UTC

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