Complete the code to create an inverted index mapping terms to documents.
PUT /my_index/_doc/1 { "content": "apple banana cherry" } GET /my_index/_search { "query": { "match": { "content": "[1]" } } }
The inverted index maps the term apple to documents containing it. Searching for apple returns matching documents.
Complete the query to find documents containing the term 'banana'.
GET /my_index/_search {
"query": {
"match": {
"content": "[1]"
}
}
}Searching for banana returns documents containing that term, using the inverted index.
Fix the error in the query to correctly search for 'cherry'.
GET /my_index/_search {
"query": {
"match": {
"content": [1]
}
}
}The term must be a string in quotes. Using "cherry" is correct syntax for Elasticsearch queries.
Fill both blanks to create a query that searches for documents containing 'apple' or 'cherry'.
GET /my_index/_search {
"query": {
"bool": {
"should": [
{ "match": { "content": [1] } },
{ "match": { "content": [2] } }
]
}
}
}The bool query with should matches documents containing either apple or cherry.
Fill all three blanks to create a filtered query that searches for 'banana' and filters documents with 'status' equal to 'active'.
GET /my_index/_search {
"query": {
"bool": {
"must": { "match": { "content": [1] } },
"filter": { "term": { "status": [2] } }
}
},
"_source": [3]
}The query matches documents containing banana and filters those with status equal to active. The _source field limits returned fields to content and status.