Hi all,
I have some troubles when I try to use Range Filter aggregation on an array.
Example of 1 document :
{
"_index": "test",
"_type": "values",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"array": [927,425,455,120]
}
}
For all my "values" document, I'd like to count, on "array" field, how many
numbers are less than 200 and how many are greater than 500.
I tried this aggregation :
GET /test/values/_search
{
"aggs" : {
"less" : {
"filter":{"range":{"array":{ "lt" : 200}}}
},
"greater" : {
"filter":{"range":{"array":{ "gt" : 500}}}
}
}
}
But the 1st filter count the number of documents which have an array
containing a value <200 and the 2nd how many have a value >500. What I'd
like is to count, for all documents, how many values (not how many
document) are <200 and how many are >500.
If I make a sum / min / max aggregation, it will be on each value in arrays
but not with a filter. Do you have an idea how to do that thing?
I did it with 2 script filters, it works, but the computing time is too bad
:
{
"aggs" : {
"less" : {
"sum":{
"script":" def sum = 0; doc['array'].values.each(){if(it < 200) sum++}; return sum;"}
},
"greater" : {
"sum":{
"script":"def sum = 0; doc['array'].values.each(){if(it > 500) sum++}; return sum;"}
}
}
Any Idea? 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/76084de4-472f-4084-9a27-9f158d018043%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.