Elasticsearch result with group by filters

I'm implementing Elasticsearch on my system, but I have a question:

I am creating a job portal, I currently use the request below to list all available positions:

GET /companies/job/_search
{
    "sort" : [
        { "post_date" : {"order" : "asc"}},
        "_score"
    ]
}

And with that, I get the result, all available positions (2357), example:

{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "hits": {
    "total": 2537,
    "max_score": 1.9790175,
    "hits": [
      {
        "_index": "companies",
        "_type": "job",
        "_id": "2",
        "_score": 1.9790175,
        "_source": {
          "name": "HTML Developer (1 - 2 Yrs Exp.)",
          "category": "Graphic Designer",
          "location": "Nolda",
          "skills": "Javascript"
        }
      },
      {
        "_index": "companies",
        "_type": "job",
        "_id": "114",
        "_score": 0.30432263,
        "_source": {
          "name": "PHP Developer (2 Yrs Exp.)",
          "category": "Engineering Job",
          "location": "Pune",
          "skills": "PHP"
        }
      }
    ]
  }
}

But I wanted to display filters in a sidebar based on this list that was returned. Similar to the attached prototype.

Example:
2357 vacancies were returned.
In the list next to, shows that of the total vacancies, grouping by categories, we have 214 are graphic designer, 514 are for engineering, etc ...
Grouping by Location, we have: 1254 for Nolda, 221 for Pune, etc ...

I would like to know, if in the same request I make the query to return all available jobs, it would be possible to also bring the groupings.

Or if I have to make two requests, one to bring all the jobs, and another to bring the groupings (and the counters for each item in the grouping).

Prototype

Yes, this is not only possible, but also a feature that Elasticsearch excels at.

The feature is called Aggregations. In a single request Elasticsearch can search and aggregate the results in many different ways.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.