Search code examples
phpelasticsearchfaceted-search

How to perform faceting to group results by other fields in Elastic Search


I have a document mapping that looks like this:

_id : integer
title: string
category: string
country: string

Given a search by 'title' i would like to get the amount of results found in all categories and all countries, so something like

countries:
   USA: 38
   UK: 17
   ES: 5
   ....

categories:
   Animals: 6
   People:  772
   Objects: 87
   ....

Is it possible to do this in Elastic Search?

Thanks


Solution

  • Yes, this is the standard behavior for faceting in Elasticsearch. Please refer to the Elasticsearch Facets documentation for more information and examples.