Executing a standard search
After having inserted documents, the most common executed action in ElasticSearch is the search. The official ElasticSearch client APIs for searching are similar to the REST one.
Getting ready
You need a working ElasticSearch cluster and required packages of the Creating a client recipe of this chapter.
The code of this recipe is in the chapter_11/searching.py
and chapter_11/searching_pyes.py
files.
How to do it...
To execute a standard query, the client search method must be called passing the query parameters as we saw in Chapter 5, Search, Queries, and Filters. The required parameters are at least the index name, the type name, and the query DSL. In the following example I'll show how to call a match all query, a term query and a filter query. We need to perform the following steps:
- We will initialize the client and populate the index as follows:
import elasticsearch from pprint import pprint es = elasticsearch.Elasticsearch() index_name = "my_index"...