0
0
Elasticsearchquery~30 mins

Why indexes organize data in Elasticsearch - See It in Action

Choose your learning style9 modes available
Why Indexes Organize Data in Elasticsearch
📖 Scenario: You are working with Elasticsearch, a tool that helps you search and organize lots of information quickly. To do this, Elasticsearch uses something called an index. Think of an index like a big, organized filing cabinet that stores your data so you can find what you need fast.
🎯 Goal: You will create a simple Elasticsearch index with some data, set a configuration for the index, write a query to find specific data, and then display the results. This will help you understand how indexes organize data to make searching easy and fast.
📋 What You'll Learn
Create an Elasticsearch index called library with three books and their authors
Add a configuration setting to the index to specify the number of shards as 1
Write a query to find books where the author is "Jane Austen"
Print the titles of the books found by the query
💡 Why This Matters
🌍 Real World
Indexes in Elasticsearch help companies quickly find information in large collections of data, like searching products in an online store or articles in a news website.
💼 Career
Understanding how to create and query indexes is important for roles like data engineers, backend developers, and search specialists who work with search engines and big data.
Progress0 / 4 steps
1
Create the Elasticsearch index with data
Create an Elasticsearch index called library and add these three books with their authors as documents: {"title": "Pride and Prejudice", "author": "Jane Austen"}, {"title": "1984", "author": "George Orwell"}, and {"title": "Emma", "author": "Jane Austen"}.
Elasticsearch
Need a hint?

Use es.index() to add each book to the library index with a unique id.

2
Add index configuration for shards
Add a configuration to the library index to set the number of shards to 1 when creating it.
Elasticsearch
Need a hint?

Use es.indices.create() with a settings dictionary to set number_of_shards to 1.

3
Write a query to find books by Jane Austen
Write a query using es.search() to find all books in the library index where the author is "Jane Austen".
Elasticsearch
Need a hint?

Use a match query inside es.search() to find documents where author is "Jane Austen".

4
Print the titles of the found books
Print the titles of the books found in the search result stored in result.
Elasticsearch
Need a hint?

Loop over result["hits"]["hits"] and print each document's title from _source.