# Adjusting Field Boost Based on Indexed Scores in Elasticsearch

**URL:** <https://discuss.elastic.co/t/adjusting-field-boost-based-on-indexed-scores-in-elasticsearch/364826>\
**Category:** Elasticsearch\
**Created:** [August 13, 2024, 11:13am UTC](https://discuss.elastic.co/t/adjusting-field-boost-based-on-indexed-scores-in-elasticsearch/364826 "2024-08-13T11:13:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gokhan\_Gunes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gokhan_gunes/32/136736_2.png) [@Gokhan\_Gunes](https://discuss.elastic.co/u/Gokhan_Gunes)\
**Post date:** [August 13, 2024, 11:13am UTC](https://discuss.elastic.co/t/adjusting-field-boost-based-on-indexed-scores-in-elasticsearch/364826/1 "2024-08-13T11:13:02Z")

</div>

**Description:**

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

Copy code

"properties": {  
"fieldScores": {  
"type": "nested",  
"properties": {  
"name": {  
"properties": {  
"value": {  
"type": "double",  
"default": 1  
},  
"weight": {  
"type": "double",  
"default": 1  
}  
}  
}  
}  
}  
}

```auto

Now, I want to adjust the boost during the search based on the `fieldScores.name.value` from the indexed data.

For example:

1. **Product 1** : Product name is "cotton swab", category is "books", brand is "xyz", and `fieldScores.name.value` = 0.
2. **Product 2** : Product name is "cotton swab 100 pieces", category is "cotton swabs", brand is "gök", and `fieldScores.name.value` = 1.
3. **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?
```

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [August 13, 2024, 4:50pm UTC](https://discuss.elastic.co/t/adjusting-field-boost-based-on-indexed-scores-in-elasticsearch/364826/2 "2024-08-13T16:50:06Z")

</div>

Hi @Gokhan_Gunes

Try use the [field value factor](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-field-value-factor).

> The `field_value_factor` function allows you to use a field from a document to influence the score.

---

<div class="post-metadata">

**Author:** ![Gokhan\_Gunes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gokhan_gunes/32/136736_2.png) [@Gokhan\_Gunes](https://discuss.elastic.co/u/Gokhan_Gunes)\
**Post date:** [August 14, 2024, 5:49pm UTC](https://discuss.elastic.co/t/adjusting-field-boost-based-on-indexed-scores-in-elasticsearch/364826/3 "2024-08-14T17:49:25Z")

</div>

**We can call it boost from doc**

"I have a query where I search across multiple fields and assign boost values to those fields. However, I want to influence the field-specific boost based on the score stored in the document.

For example, if a product's name is very generic, I want it to receive a lower score from the name field. But if the search term is not related to the product name and is instead related to the product category, the document should get its score from the categoryName field and not be penalized by the name field score. Essentially, I want the boost value for the name field to be influenced by the score stored in the document for that field, but only when searching within the name field."
