Now let's look at how we can search Elasticsearch using the Elasticsearch Python library. We will perform a simple search on the Star Wars index.
Performing an Elasticsearch query with the Python API
Getting ready
Make sure to modify the connection URL in the samples to your URL.
How to do it
The code for the search is in the 11/02/search_starwars_by_haircolor.py script, and can be run by simply executing the script. This is a fairly simple search to find the characters whose hair color is blond:
- The main portion of the code is:
es = Elasticsearch(
[
...