Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch, get average document length

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 length for a specific index?

like image 562
CentAu Avatar asked Feb 05 '15 02:02

CentAu


1 Answers

The _size mapping field, if enabled, should give you the size of each document for free. Combining this with the avg aggregation should get you what you want. Something like:

{
  "query" : {"match_all" : {}},
  "aggs" : {"avg_size" : {"avg" : {"terms" : {"field" : "_size"}}}}
}
like image 192
rchang Avatar answered Sep 25 '22 06:09

rchang