# Boosting documents performance (Terms vs Should)

**URL:** <https://discuss.elastic.co/t/boosting-documents-performance-terms-vs-should/245018>\
**Category:** Elasticsearch\
**Created:** [August 14, 2020, 1:28pm UTC](https://discuss.elastic.co/t/boosting-documents-performance-terms-vs-should/245018 "2020-08-14T13:28:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kushikawa](https://avatars.discourse-cdn.com/v4/letter/k/8baadc/32.png) [@Kushikawa](https://discuss.elastic.co/u/Kushikawa)\
**Post date:** [August 14, 2020, 1:28pm UTC](https://discuss.elastic.co/t/boosting-documents-performance-terms-vs-should/245018/1 "2020-08-14T13:28:27Z")

</div>

Hi, I have something similar to the following document:

```auto
{
  "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:

```auto
GET /products/_search
{
  "query": {
    "function_score": {
      "functions": [
        {
          "filter": {
            "terms":{
              "skus": ["54857", "42687"] // 0 < n_skus < 50
            }
          },
          "weight": 1.2
        }
      ],
      "query": { ... } // boolean query
    }
  }
}

```

```auto
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!!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 11, 2020, 1:28pm UTC](https://discuss.elastic.co/t/boosting-documents-performance-terms-vs-should/245018/2 "2020-09-11T13:28:42Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
