If we search for "Padma Priya" and is there any exact match then we need to show that result first but what happening is It's showing "Padma" posts first only because of keyword density and weightage.
If there is no "Padma Priya" then we want to show "Padma" results and "Priya" Results as per keyword density and weightage.
If we found both "Padma Priya" Keyword in Text and the URL then we need to give high priority to URL then Title after that page content.
This is my query:
{
searchBody = {
"from" : 0,
"size" : size,
"query": {
"bool": {
"should" : [
{
"match": {
"location": {
"query": q,
// "boost": 5
}
}
},
{
"match": {
"title": {
"query": q,
"boost": 5
}
}
}
,
{
"match": {
"description": {
"query": q
}
}
}
]
}
}
};
}
As shown in ES boost doc first query, you can see how to give more boost/priority to your
title
fields than the page content which is very common use-case.for your first use-case of If we search for "Padma Priya" and is there any exact match, you need to combine the phrase query with your existing query to get the result at the top.
Concept will be clear by below example:
Index sample doc, index will be created automatically.
Index another doc which has
padam priya
as a phrase:Search query
And search result