# Performance on multi term query with "should" clause

**URL:** https://discuss.elastic.co/t/performance-on-multi-term-query-with-should-clause/108102
**Category:** Elasticsearch
**Created:** [November 17, 2017, 10:07am UTC](https://discuss.elastic.co/t/performance-on-multi-term-query-with-should-clause/108102 "2017-11-17T10:07:37Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![imoghira](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/imoghira/32/24367_2.png) [@imoghira](https://discuss.elastic.co/u/imoghira)
#### Post date: [November 17, 2017, 10:07am UTC](https://discuss.elastic.co/t/performance-on-multi-term-query-with-should-clause/108102/1 "2017-11-17T10:07:37Z")

</div>

I am working on this query which involves term match of around 100 queries with "should" clause. It goes something like this.

"query": {  
"function\_score": {  
"query": {  
"filtered": {  
"query": {  
"bool": {  
"must": [  
{  
"match\_all": [

```
            ]
          }
        ],
        "should": [
          {
            "match": {
              "product_id": {
                "query": "1234",
                "boost": 15750
              }
            }
          },
          {
            "match": {
              "product_id": {
                "query": "83127",
                "boost": 13446
              }
            }
          },
          {
            "match": {
              "product_id": {
                "query": "3123",
                "boost": 6894
              }
            }
          },
          {
            "match": {
              "product_id": {
                "query": "43243",
                "boost": 6246
              }
            }
          },
          {
            "match": {
              "product_id": {
                "query": "645464",
                "boost": 6102
              }
            }
          },
          {
            "match": {
              "product_id": {
                "query": "757563",
                "boost": 5814
              }

```

...

where the should clause is around 100 queries. The idea being differential boost for the products in our custom ranking algorithm.

However I see the steep rise in the CPU load. Is there any way we can optimize this?  
The mapping for product\_id field is:  
'product\_id' =\> [  
'type' =\> 'string',  
'index' =\> 'not\_analyzed',  
]

---

<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: [December 15, 2017, 10:07am UTC](https://discuss.elastic.co/t/performance-on-multi-term-query-with-should-clause/108102/2 "2017-12-15T10:07:40Z")

</div>

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