Count of values on array field

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.
For more options, visit https://groups.google.com/groups/opt_out.

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 :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 2 août 2013 à 07:36, Qi Peng 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.
For more options, visit 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.
For more options, visit https://groups.google.com/groups/opt_out.

1 Like

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 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 :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 2 août 2013 à 07:36, Qi Peng 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.
For more options, visit 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.
For more options, visit https://groups.google.com/groups/opt_out.

--
Perry | 彭琪
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.
For more options, visit https://groups.google.com/groups/opt_out.

1 Like