Issue
Nested field name is transactions.
Each document has a list of transactions.
I wish to aggregate on the number of transactions. Information i seek is the number Nf documents with more than one transaction.
I tried the following :
"aggs": {
"tx_count": {
"terms": {
"script": {
"inline": "if(doc['transactions'].size>1){return 1;} else {return 0;}"
}
}
}
}
I also tried using this aggregation within a nested aggregation. Is there a way to do this?
I'm on ES version 5.6 currently.
Solution
You can use params._source
to calculate the transactions
length:
{
"size": 0,
"aggs": {
"tx_count": {
"terms": {
"script": {
"inline": "if (params._source['transactions'].size() > 1) { return 1; } else { return 0; }"
}
}
}
}
}
BTW notice that it's .size()
, not .size
.
Answered By - Joe - ElasticsearchBook.com Answer Checked By - Robin (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.