Faceting
ElasticSearch is a full text search engine that aims to provide search results on the basis of our queries. However, sometimes we would like to get more. For example, we would like to get aggregated data that is calculated on the result set we get, such as the number of documents priced between 100 and 200 dollars or the most common tags in the results documents. In order to do that, ElasticSearch provides a faceting module that is responsible for providing such data. In this chapter we will discuss different faceting methods provided by ElasticSearch.
Document structure
For the purpose of discussing faceting, we'll use a very simple index structure for our documents. It will contain the identifier of the document, document date, a multivalued field that can hold words describing our document (the tags
field), and a field holding numeric information (the total
field). Our mappings could look like this:
{ "mappings" : { "doc" : { "properties" : { "id" : { ...