Complete the code to create an index named 'books'.
PUT /[1]The command PUT /books creates an index named 'books' in Elasticsearch.
Complete the code to add a document with id '1' to the 'books' index.
PUT /books/_doc/[1] { "title": "Elasticsearch Basics", "author": "John Doe" }
The document id is '1', so the URL should end with /_doc/1.
Fix the error in the search query to find documents with 'Elasticsearch' in the title.
GET /books/_search
{
"query": {
"match": {
"title": "[1]"
}
}
}The correct search term is exactly 'Elasticsearch' to match the title field.
Fill both blanks to create a query that searches for 'John' in the author field and sorts results by 'publish_date' descending.
GET /books/_search
{
"query": {
"match": {
"[1]": "John"
}
},
"sort": [
{"[2]": {"order": "desc"}}
]
}The query searches the 'author' field for 'John' and sorts by 'publish_date' in descending order.
Fill the blanks to create an aggregation that counts documents per 'genre' and filters genres with more than 5 documents.
GET /books/_search
{
"size": 0,
"aggs": {
"genres_count": {
"terms": {
"field": "[1]",
"min_doc_count": [2]
}
}
},
"query": {
"match_all": {}
}
}The aggregation counts documents by 'genre' field and filters to only include genres with at least 5 documents.