Complete the code to retrieve the relevance score (_score) for each search hit.
{
"query": {
"match": {
"message": "search text"
}
},
"_source": ["message"],
"fields": ["[1]"]
}The relevance score is stored in the _score field in Elasticsearch search hits.
Complete the code to sort search results by their relevance score in descending order.
{
"query": {
"match_all": {}
},
"sort": [
{"[1]": {"order": "desc"}}
]
}Sorting by _score in descending order shows the most relevant results first.
Fix the error in the query to correctly boost documents with the term 'urgent' to increase their relevance score.
{
"query": {
"bool": {
"should": [
{"match": {"message": "[1]"}},
{"match": {"message": {"query": "urgent", "boost": 2}}}
]
}
}
}The first match query should search for the main term, here 'urgent', to apply boosting properly.
Fill both blanks to create a function score query that multiplies the relevance score by 3 for documents with 'priority' in the tag field.
{
"query": {
"function_score": {
"query": {"match_all": {}},
"functions": [
{
"filter": {"term": {"tags": "[1]"}},
"weight": [2]
}
]
}
}
}The filter should match the tag 'priority' and the weight should be 3 to multiply the score accordingly.
Fill all three blanks to build a query that boosts documents containing 'error' in the message field by 5 and sorts results by relevance score descending.
{
"query": {
"function_score": {
"query": {"match": {"message": "[1]"}},
"boost": [2],
"boost_mode": "multiply"
}
},
"sort": [
{"[3]": {"order": "desc"}}
]
}The query matches 'error', boosts by 5, and sorts by _score descending to prioritize relevant results.