# Count of values on array field

**URL:** <https://discuss.elastic.co/t/count-of-values-on-array-field/13039>\
**Category:** Elasticsearch\
**Created:** [August 2, 2013, 5:36am UTC](https://discuss.elastic.co/t/count-of-values-on-array-field/13039 "2013-08-02T05:36:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Perry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/perry/32/2185_2.png) [@Perry](https://discuss.elastic.co/u/Perry)\
**Post date:** [August 2, 2013, 5:36am UTC](https://discuss.elastic.co/t/count-of-values-on-array-field/13039/1 "2013-08-02T05:36:06Z")

</div>

Hi, I have an index like this,

{  
"id":1,  
"time":["2013-03-04", "2013-03-05"]  
},  
{  
"id":2,  
"time":["2013-03-05"]  
}

I want to do a query based on two conditions:

1. range on time field to get results after "2013-03-04"
2. count of values on time field is more than 1

Is this possible in ElasticSearch, or do I need a filter to match the  
second condition?

thx.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 2, 2013, 6:11am UTC](https://discuss.elastic.co/t/count-of-values-on-array-field/13039/2 "2013-08-02T06:11:36Z")

</div>

The best thing to do here is IMHO to add a new field named "num\_of\_dates which contain your array size and then query on it.

My 2 cents

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 2 août 2013 à 07:36, Qi Peng [perrywky@gmail.com](mailto:perrywky@gmail.com) a écrit :

Hi, I have an index like this,

{  
"id":1,  
"time":["2013-03-04", "2013-03-05"]  
},  
{  
"id":2,  
"time":["2013-03-05"]  
}

I want to do a query based on two conditions:  
range on time field to get results after "2013-03-04"  
count of values on time field is more than 1

Is this possible in ElasticSearch, or do I need a filter to match the second condition?

thx.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Perry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/perry/32/2185_2.png) [@Perry](https://discuss.elastic.co/u/Perry)\
**Post date:** [August 2, 2013, 10:09am UTC](https://discuss.elastic.co/t/count-of-values-on-array-field/13039/3 "2013-08-02T10:09:19Z")

</div>

thx, I googled and found this way

"filter" : {  
"script" : {  
"script" : "doc['time'].values.length \> 1"  
}  
}

On Fri, Aug 2, 2013 at 2:11 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> The best thing to do here is IMHO to add a new field named "num\_of\_dates  
> which contain your array size and then query on it.
> 
> My 2 cents
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 2 août 2013 à 07:36, Qi Peng [perrywky@gmail.com](mailto:perrywky@gmail.com) a écrit :
> 
> Hi, I have an index like this,
> 
> {  
> "id":1,  
> "time":["2013-03-04", "2013-03-05"]  
> },  
> {  
> "id":2,  
> "time":["2013-03-05"]  
> }
> 
> I want to do a query based on two conditions:
> 
> 1. range on time field to get results after "2013-03-04"
> 2. count of values on time field is more than 1
> 
> Is this possible in Elasticsearch, or do I need a filter to match the  
> second condition?
> 
> thx.
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Perry | 彭琪  
[http://pengqi.me](http://pengqi.me)

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:23am UTC](https://discuss.elastic.co/t/count-of-values-on-array-field/13039/4 "2017-07-06T02:23:13Z")

</div>


