Hi, I have something similar to the following document:
{
"title": "Alisha Solid Women's Cycling Shorts",
"sku":["54855","54856","54857","54858","54859"]
},
{
"title": "Vishudh Printed Women's Anarkali Kurta",
"sku":["42685","42686","42687","42688","42689"]
},
{
"title": "Mario Gotze Women's Printed Casual Orange Shirt",
"sku":["52526","52527","52528","52529"]
}
What I have so far is a basic search on these two attributes. But now I want to boost some documents based on another business rule that should increase the score for specific skus, for example, if I pass ["54857", "42687"], the relevance of the first two documents must be increased.
I found two ways to achieve this result using function_score:
GET /products/_search
{
"query": {
"function_score": {
"functions": [
{
"filter": {
"terms":{
"skus": ["54857", "42687"] // 0 < n_skus < 50
}
},
"weight": 1.2
}
],
"query": { ... } // boolean query
}
}
}
GET /products/_search
{
"query": {
"function_score": {
"functions": [
{
"filter": {
"bool":{
"should":[
{
"term": {
"skus": "54857"
}
},
{
"term": {
"skus": "42687"
}
}
]
}
},
"weight": 1.2
}
],
"query": { ... } // boolean query
}
}
}
Some considerations regarding the list of skus:
- it is built dynamically at run time (can't just add weight param to the documents)
- the number of skus on the list to be boosted can be up to 50 elements
- the number os skus in each document is also dynamic and can be more than 50
I would be grateful if someone helped me understand:
- In terms of performance, which of the two approaches is the best for my use case?
- Is there any other approach I can use to boost documents that leads me to the same result given by the two queries above?
Thanks in advance!!