# Find length of array in that doc

**URL:** <https://discuss.elastic.co/t/find-length-of-array-in-that-doc/155120>\
**Category:** Elasticsearch\
**Created:** [November 2, 2018, 6:32am UTC](https://discuss.elastic.co/t/find-length-of-array-in-that-doc/155120 "2018-11-02T06:32:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GitSpree23](https://avatars.discourse-cdn.com/v4/letter/g/65b543/32.png) [@GitSpree23](https://discuss.elastic.co/u/GitSpree23)\
**Post date:** [November 2, 2018, 6:32am UTC](https://discuss.elastic.co/t/find-length-of-array-in-that-doc/155120/1 "2018-11-02T06:32:11Z")

</div>

I have a field in my index which is an integer array. I want to add another field which contains the count of the number of elements.

Even an API call that gives the count is fine.

I have found something relevant :  
"script" : "doc['MyField'].values.size()"

But I don't know how & where to use it.  
Please help!

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [November 2, 2018, 7:12am UTC](https://discuss.elastic.co/t/find-length-of-array-in-that-doc/155120/2 "2018-11-02T07:12:23Z")

</div>

I didn't see you cross-posted this, but here is your answer

> <https://stackoverflow.com/questions/53113822/find-length-size-of-the-array-type-field-in-each-doc/53113928#53113928>

  
Hope it helps 😉

---

<div class="post-metadata">

**Author:** ![GitSpree23](https://avatars.discourse-cdn.com/v4/letter/g/65b543/32.png) [@GitSpree23](https://discuss.elastic.co/u/GitSpree23)\
**Post date:** [November 2, 2018, 8:51am UTC](https://discuss.elastic.co/t/find-length-of-array-in-that-doc/155120/3 "2018-11-02T08:51:33Z")

</div>

Thanks 😄 @val

Could you plz explain "ctx"?

Also, is there a way to do this in the logstash config? It would save time in large file size. Because I'm getting a "gateway timeout" in case of actual 22GB data.

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [November 2, 2018, 12:34pm UTC](https://discuss.elastic.co/t/find-length-of-array-in-that-doc/155120/4 "2018-11-02T12:34:14Z")

</div>

I'm not sure how Logstash would help in this case. Update by query can only be called via the REST API or through a client library.

Also note that Gateway timeout doesn't mean that the task is killed, just that your client connection has timed out, but the task is still ongoing in the background. If you run the command below, you'll see that the update is still running:

```
GET _tasks?actions=*byquery&detailed=true
```

---

<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:** [November 30, 2018, 12:34pm UTC](https://discuss.elastic.co/t/find-length-of-array-in-that-doc/155120/5 "2018-11-30T12:34:26Z")

</div>

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