ElasticSearch ElasticSearch Search & Query DSL 1 — Questions and Answers
Question 1: What is the Query DSL in Elasticsearch?
- A command-line tool for managing clusters
- A JSON-based language for defining queries (Correct answer)
- A SQL-compatible query interface
- A scripting language for data transformation
Correct answer: A JSON-based language for defining queries
The Query DSL (Domain Specific Language) is a JSON-based interface that allows you to build complex queries using a flexible and expressive syntax.
Question 2: What is the difference between a 'filter' context and a 'query' context in Elasticsearch?
- Filter context scores results; query context does not
- Query context calculates relevance scores; filter context only checks if documents match without scoring (Correct answer)
- Filter context is used for aggregations only
- There is no functional difference
Correct answer: Query context calculates relevance scores; filter context only checks if documents match without scoring
Query context determines how well a document matches and computes a relevance score, while filter context only checks if a document matches with no scoring and is cacheable.
Question 3: What does a 'match' query do in Elasticsearch?
- Finds documents where a field exactly equals a value
- Analyzes the input text and finds documents matching the analyzed terms (Correct answer)
- Finds documents based on a range of values
- Matches documents by their document ID
Correct answer: Analyzes the input text and finds documents matching the analyzed terms
A match query analyzes the query string using the field's analyzer and then searches for documents containing those terms.
Question 4: Which query type is best for exact value matching on keyword fields in Elasticsearch?
- match
- term (Correct answer)
- match_phrase
- fuzzy
Correct answer: term
A 'term' query finds documents that contain the exact term specified, without any analysis, making it ideal for keyword, numeric, or date fields.
Question 5: What is a 'bool' query in Elasticsearch used for?
- Searching for boolean true/false field values
- Combining multiple query clauses using must, should, must_not, and filter (Correct answer)
- Performing fuzzy matching on text fields
- Filtering documents by existence of a field
Correct answer: Combining multiple query clauses using must, should, must_not, and filter
A bool query combines multiple query clauses using must (required), should (optional), must_not (exclude), and filter (required, no score) logic.
Question 6: What does the 'match_phrase' query do in Elasticsearch?
- Matches documents where terms appear in any order
- Matches documents where terms appear as an exact phrase in the specified order (Correct answer)
- Performs a wildcard phrase search
- Matches documents containing any single term from the phrase
Correct answer: Matches documents where terms appear as an exact phrase in the specified order
A match_phrase query analyzes the text and searches for documents where all the terms appear in the same order as the query phrase.
What is the Query DSL in Elasticsearch?