...

/

Solution: Search on Elasticsearch

Solution: Search on Elasticsearch

Verify your answers to the search challenge.

Solution 1: Products with the name field containing "Samsung"

To solve this query challenge, we can use the match query, which performs a full-text search on the specified field, making it suitable for searching text-based fields like the name field.

To construct the query, we need to send a search request to the products index and specify the query type as match for the name field. The query text should be set as "Samsung".

Press + to interact
GET /products/_search
{
"query": {
"match": {
"name": "Samsung"
}
}
}

Solution 2: "Apple" products in the $500–$1000 price range

To solve this query challenge, we can utilize a bool query, and within its must clause, include a range query to filter the products based on the price range of $500 to $1000 and a term query to search for an exact match of the brand "Apple".

Press + to interact
GET /products/_search
{
"query": {
"bool": {
"must": [
{
"range": {
"price": {
"gte": 500,
"lte": 1000
}
}
},
{
"term": {
"brand": "Apple"
}
}
]
}
}
}

Solution 3: Products with the description field containing the exact phrase "premium ultrabook"

To solve this query challenge, we can utilize the match_phrase query to ensure that the entire phrase ...