Book Image

ElasticSearch Cookbook

By : Alberto Paro
Book Image

ElasticSearch Cookbook

By: Alberto Paro

Overview of this book

Table of Contents (20 chapters)
ElasticSearch Cookbook Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Executing a search with aggregations


Searching for results is obviously the main activity of a search engine; thus, aggregations are very important because they often help to augment the results.

Aggregations are executed along with the search by doing an analysis on the searched results.

Getting ready

You need a working ElasticSearch cluster and the packages used in the Creating a client recipe in this chapter.

The code of this recipe is in the chapter_11/aggregation.py and chapter_11/aggregation_pyes.py files, available in the code bundle of this book and on GitHub (https://github.com/aparo/elasticsearch-cookbook-second-edition).

How to do it...

In order to extend a query with aggregations, you need to define an aggregation section similar to what you saw in Chapter 6, Aggregations. In the case of the official ElasticSearch client, you can add the aggregation DSL to the search dictionary in order to provide aggregations results. To do this, perform the following steps:

  1. Initialize the client and...