ElasticSearch ElasticSearch Search & Query DSL 2 — Questions and Answers
Question 1: What is a 'fuzzy' query in Elasticsearch?
- A query that returns all documents regardless of match
- A query that finds terms similar to the search term based on edit distance (Correct answer)
- A query for searching nested documents
- A query that performs partial word matching using wildcards
Correct answer: A query that finds terms similar to the search term based on edit distance
A fuzzy query finds terms that are similar to the specified term using Levenshtein edit distance, allowing for typo-tolerant searches.
Question 2: What does the 'size' parameter control in an Elasticsearch search request?
- The number of shards searched
- The maximum number of hits returned in the response (Correct answer)
- The size of each document returned
- The number of aggregation buckets returned
Correct answer: The maximum number of hits returned in the response
The 'size' parameter specifies how many matching documents to include in the search results; the default is 10.
Question 3: What is the purpose of the '_source' field in an Elasticsearch search response?
- It identifies the node that handled the search
- It contains the original JSON document that was indexed (Correct answer)
- It lists the shards that were searched
- It shows the query execution plan
Correct answer: It contains the original JSON document that was indexed
The '_source' field in a search response contains the original JSON document that was indexed, allowing you to retrieve the stored document data.
Question 4: What is 'pagination' in Elasticsearch and which parameters are used for it?
- Splitting large indices using 'split' and 'shrink'
- Using 'from' and 'size' parameters to retrieve a subset of results (Correct answer)
- Using the 'scroll' API to paginate all results
- Dividing results into buckets using aggregations
Correct answer: Using 'from' and 'size' parameters to retrieve a subset of results
Basic pagination in Elasticsearch uses the 'from' parameter to specify the starting offset and 'size' to control the number of results returned.
Question 5: What does the Elasticsearch 'highlight' feature do?
- Marks documents as important in the index
- Returns snippets of matched text with search terms highlighted (Correct answer)
- Boosts the relevance score of specific fields
- Adds color-coding to the admin dashboard
Correct answer: Returns snippets of matched text with search terms highlighted
The highlight feature returns fragments of matched text from the document with the query terms wrapped in highlight tags for display purposes.
Question 6: What is the 'explain' API in Elasticsearch used for?
- Documenting an index's mapping
- Showing how a relevance score was calculated for a specific document (Correct answer)
- Explaining cluster topology
- Providing query optimization suggestions
Correct answer: Showing how a relevance score was calculated for a specific document
The explain API computes a score for a specific document and provides detailed information about how that score was calculated.
What is a 'fuzzy' query in Elasticsearch?