Is there any better way in elasticsearch (other than issuing a match all query and manually averaging over the length of all returned documents) to get the average document
I have used this code (I have the _source enabled)
{
"query" : {"match_all" : {}},
"aggs":{
"avg_length" : { "avg" : { "script" : "_source.toString().length()"}}
}
}
Well, the chars .. .if the string are UTF-8 to get the bytes:
{
"query" : {"match_all" : {}},
"aggs":{
"avg_length" : { "avg" : { "script" : "_source.toString().getBytes(\"UTF-8\").length"}}
}
}