# Scripting with ES - size of array of objects

**URL:** <https://discuss.elastic.co/t/scripting-with-es-size-of-array-of-objects/22350>\
**Category:** Elasticsearch\
**Created:** [February 24, 2015, 10:48am UTC](https://discuss.elastic.co/t/scripting-with-es-size-of-array-of-objects/22350 "2015-02-24T10:48:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DH1](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@DH1](https://discuss.elastic.co/u/DH1)\
**Post date:** [February 24, 2015, 10:48am UTC](https://discuss.elastic.co/t/scripting-with-es-size-of-array-of-objects/22350/1 "2015-02-24T10:48:53Z")

</div>

Hi, everyone.

I'm currently facing a problem I can't seem to solve by myself, so, I came  
to seek the help of ES users more seasoned than I happen to be.

I need to calculate the max size or a nested array of objects apprearing in  
my docs.

So, I'm using a statistical facet like this one :

{  
"query" : {  
"match\_all" : {}  
},  
"facets" : {  
"stat1" : {  
"statistical" : {  
"script" : "doc['path\_to\_nested\_object'].values.size()"  
}  
}  
}  
}

this gives me an error, witch seems to be normal because I can only use  
that script on leaf nodes. So, I do something like this :

{  
"query" : {  
"match\_all" : {}  
},  
"facets" : {  
"stat1" : {  
"statistical" : {  
"script" : "doc['path-to\_nested\_object.code'].values.size()"  
}  
}  
}  
}

This gives me a result, where the "max" value of the facet should be what  
I'm looking for.

BUT !

It seems that when the script runs, it counts the distinct values, and not  
all the values. In my example, several of those nested objects have the  
same code, within the same doc.

Problem is, a disctinct value count is utterly useless to me.

I really need to count either

1. the size of the array of objects (that would be the best)
2. the size of the array of the values of a leaf node within the nested  
object, _reapeted values included._

Is one of these possible?  
Using another language than mvel?  
Using native java scripting, maybe? (any exemple of that one would be  
GREATLY appreciated).

Thanks !

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0478dc4d-3976-4f7e-97ae-18fc9645560a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0478dc4d-3976-4f7e-97ae-18fc9645560a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![DH1](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@DH1](https://discuss.elastic.co/u/DH1)\
**Post date:** [February 25, 2015, 7:39am UTC](https://discuss.elastic.co/t/scripting-with-es-size-of-array-of-objects/22350/2 "2015-02-25T07:39:39Z")

</div>

No one met that kind of problems?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/49c9cf7c-6dab-444d-a426-64c3086e6419%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/49c9cf7c-6dab-444d-a426-64c3086e6419%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:30am UTC](https://discuss.elastic.co/t/scripting-with-es-size-of-array-of-objects/22350/3 "2017-07-06T00:30:18Z")

</div>


