I’m working on an e-commerce site where products are indexed in Elasticsearch. Users search through fields like brand, publisher, product_name, and category. I typically give the highest boost to the name field when matching search queries. However, some product names are unique, and I want to adjust the boost based on a pre-determined score for each product’s name field that I store during indexing.
Here’s how I’ve structured my Elasticsearch index for scoring:
json
"properties": {
"fiedScores": {
"type": "nested",
"properties": {
"name": {
"properties": {
"value": {
"type": "double",
"default": 1
},
"weight": {
"type": "double",
"default": 1
}
}
}
}
}
}
Now, I want to adjust the boost during the search based on the fieldScores.name.value from the indexed data.
For example:
Product 1: Product name is “cotton swab”, category is “books”, brand is “xyz”, and fieldScores.name.value = 0.
Product 2: Product name is “cotton swab 100 pieces”, category is “cotton swabs”, brand is “gök”, and fieldScores.name.value = 1.
Product 3: Product name is “cotton swab 3000 pieces”, category is “cotton swabs”, brand is “gök”, and fieldScores.name.value = 1.
When a user searches for “cotton swab”, the first product should not receive any boost from the name field despite the exact match because fieldScores.name.value is 0. However, the second and third products should receive a boost from the name field as their fieldScores.name.value is 1.
I need help constructing an Elasticsearch query that adjusts the boost for the name field based on the stored fieldScores.name.value. How can I achieve this?