What is the main use of the text field type in Elasticsearch?
The text field type is used for full-text search. It breaks the content into words (tokens) so you can search for individual words or phrases inside the text.
Click to reveal answer
beginner
What is the keyword field type best suited for in Elasticsearch?
The keyword field type is used for structured data like IDs, tags, or categories. It stores the whole value exactly as it is, without breaking it into words, so it is good for exact matches and sorting.
Click to reveal answer
intermediate
How does Elasticsearch treat text fields differently from keyword fields during indexing?
Text fields are analyzed and broken into tokens (words) for searching, while keyword fields are not analyzed and stored as a single token for exact matching.
Click to reveal answer
beginner
Can you use keyword fields for full-text search in Elasticsearch?
No, keyword fields are not suitable for full-text search because they do not break the text into words. They are meant for exact matches and aggregations.
Click to reveal answer
beginner
Why might you choose a text field over a keyword field for a user comment?
Because user comments are long and need to be searched by words or phrases, a text field is better since it allows full-text search by breaking the comment into tokens.
Click to reveal answer
Which Elasticsearch field type should you use to store a product ID for exact matching?
Akeyword
Btext
Cinteger
Ddate
✗ Incorrect
Product IDs are exact values, so the keyword field type is best for exact matching.
What happens to a text field during indexing in Elasticsearch?
AIt is stored as a single token without changes
BIt is converted to a number
CIt is ignored
DIt is broken into tokens (words) for searching
✗ Incorrect
Text fields are analyzed and broken into tokens to allow full-text search.
Which field type is better for sorting values alphabetically in Elasticsearch?
Atext
Bfloat
Ckeyword
Dboolean
✗ Incorrect
Keyword fields store exact values and are suitable for sorting.
Can you perform phrase searches on a keyword field?
ANo, because it is not tokenized
BYes, because it is tokenized
CYes, but only for numbers
DNo, because it is ignored
✗ Incorrect
Keyword fields are not tokenized, so phrase searches are not possible.
Which field type would you use for storing a user's full name if you want to search by parts of the name?
Akeyword
Btext
Cinteger
Ddate
✗ Incorrect
Text fields allow searching by parts of the name because they are tokenized.
Explain the difference between the text and keyword field types in Elasticsearch.
Think about how the data is stored and searched.
You got /4 concepts.
When would you choose a keyword field over a text field in Elasticsearch?
Consider the type of search or operation you want to perform.
You got /4 concepts.
Practice
(1/5)
1. Which Elasticsearch field type should you use if you want to perform full-text search inside sentences?
easy
A. text
B. keyword
C. integer
D. date
Solution
Step 1: Understand the purpose of text fields
Text fields are designed for full-text search, allowing analysis and tokenization of sentences.
Step 2: Compare with keyword fields
Keyword fields are for exact matches and do not analyze the text, so they are not suitable for searching inside sentences.
Final Answer:
text -> Option A
Quick Check:
Full-text search = text [OK]
Hint: Full-text search needs analyzed text fields [OK]
Common Mistakes:
Choosing keyword for full-text search
Confusing integer or date types with text
Thinking keyword fields tokenize text
2. Which of the following is the correct way to define a keyword field in an Elasticsearch mapping?
easy
A. "name": { "type": "text" }
B. "name": { "type": "keyword" }
C. "name": { "type": "string" }
D. "name": { "type": "fulltext" }
Solution
Step 1: Recall Elasticsearch field types
Elasticsearch uses "keyword" as the type for exact match fields.
Step 2: Identify the correct syntax
"keyword" is the correct type name; "text" is for analyzed fields, "string" and "fulltext" are invalid types.
Final Answer:
"name": { "type": "keyword" } -> Option B
Quick Check:
Keyword field syntax = "name": { "type": "keyword" } [OK]
Hint: Keyword type is exactly "keyword" in mapping [OK]