Executing statistical facets
The core of real-time analytics is the statistical facet. It works on numerical fields and in one-shot is able to compute several numerical metrics.
Getting ready
You need a working ElasticSearch cluster and an index populated with the script available in online code.
How to do it...
For executing statistical facets, we will perform the steps given as follows:
We need to compute two different statistical facets, that are:
price statistic
age statistic
The query to execute these facets is:
curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true&size=0' -d '{ "query": { "match_all": {} }, "facets": { "age" : { "statistical" : { "field" : "age", } }, "price" : { "statistical" : { "field" : "price", } } } }'
The result will be:
{ "took" : 12, "timed_out" : false, "_shards" : { "total" : 5, "successful" ...