# What is the optimal way to check if array is not empty in function\_score query?

**URL:** <https://discuss.elastic.co/t/what-is-the-optimal-way-to-check-if-array-is-not-empty-in-function-score-query/59744>\
**Category:** Elasticsearch\
**Created:** [September 4, 2016, 6:40am UTC](https://discuss.elastic.co/t/what-is-the-optimal-way-to-check-if-array-is-not-empty-in-function-score-query/59744 "2016-09-04T06:40:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lessless](https://avatars.discourse-cdn.com/v4/letter/l/bc8723/32.png) [@lessless](https://discuss.elastic.co/u/lessless)\
**Post date:** [September 4, 2016, 6:40am UTC](https://discuss.elastic.co/t/what-is-the-optimal-way-to-check-if-array-is-not-empty-in-function-score-query/59744/1 "2016-09-04T06:40:25Z")

</div>

Hello,

In our documents, there is an array field which holds URLs to the entity pictures. Naturally, we want to score documents with pictures present higher than documents w/o pictures.

According to my experience, we either can add a new field to cache amount of entries in the `photos` array, something like `photos_count` or use dynamic scripting to check `photos` length.

We don't have any problems with performance just yet, but, I still wonder if there is any other, more straightforward way to prioritize documents which `photos` array is not empty.

---

<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 5, 2017, 10:22pm UTC](https://discuss.elastic.co/t/what-is-the-optimal-way-to-check-if-array-is-not-empty-in-function-score-query/59744/2 "2017-07-05T22:22:40Z")

</div>


