0
0
Elasticsearchquery~30 mins

Text vs keyword field types in Elasticsearch - Hands-On Comparison

Choose your learning style9 modes available
Text vs Keyword Field Types in Elasticsearch
📖 Scenario: You are building a simple search system for a small online bookstore. You want to store book information in Elasticsearch. Some fields need to be searchable by full text, while others need exact matching.
🎯 Goal: Create an Elasticsearch index mapping that uses text and keyword field types correctly. Then add a document and query it to see the difference.
📋 What You'll Learn
Create an index mapping with a title field of type text
Create an index mapping with an isbn field of type keyword
Index a document with a sample book title and ISBN
Query the document by full text search on title
Query the document by exact match on isbn
💡 Why This Matters
🌍 Real World
Online stores and libraries use Elasticsearch to let users search books by title (full text) and filter by ISBN or categories (exact match).
💼 Career
Understanding <code>text</code> vs <code>keyword</code> fields is essential for building efficient search applications and indexing data correctly in Elasticsearch.
Progress0 / 4 steps
1
Create index mapping with title as text and isbn as keyword
Create an index called books with a mapping where title is of type text and isbn is of type keyword. Use the Elasticsearch PUT API with the exact JSON structure shown.
Elasticsearch
Need a hint?

Use the PUT method to create the index with the mapping inside the mappings key.

2
Index a document with title and isbn
Index a document into the books index with title set to "The Great Gatsby" and isbn set to "9780743273565". Use the POST API with the exact JSON body shown.
Elasticsearch
Need a hint?

Use POST /books/_doc to add the document with the given fields.

3
Search the document by full text on title
Write a search query using the GET /books/_search API that searches for the word "Great" in the title field using a match query.
Elasticsearch
Need a hint?

Use a match query on the title field to find documents containing the word "Great".

4
Search the document by exact match on isbn
Write a search query using the GET /books/_search API that finds the document with isbn exactly equal to "9780743273565" using a term query.
Elasticsearch
Need a hint?

Use a term query on the isbn field to find the exact match.