# Will Elasticsearch optimize dsl query?

**URL:** <https://discuss.elastic.co/t/will-elasticsearch-optimize-dsl-query/288588>\
**Category:** Elasticsearch\
**Created:** [November 8, 2021, 6:07am UTC](https://discuss.elastic.co/t/will-elasticsearch-optimize-dsl-query/288588 "2021-11-08T06:07:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CHU\_XU](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chu_xu/32/45946_2.png) [@CHU\_XU](https://discuss.elastic.co/u/CHU_XU)\
**Post date:** [November 8, 2021, 6:07am UTC](https://discuss.elastic.co/t/will-elasticsearch-optimize-dsl-query/288588/1 "2021-11-08T06:07:06Z")

</div>

Hi there,  
I have a program to convert some text into Elasticsearch dsl query. For some reasons it generates complex bool query which somethimes is actually can be simplified, for example:

```auto
{
    "query":{
        "bool":{
            "should":[
                {
                    "bool":{
                        "must":[
                            {
                                "bool":{
                                    "should":[
                                        {
                                            "multi_match":{
                                                "fields":[
                                                    "*"
                                                ],
                                                "query":"kid",
                                                "type":"best_fields"
                                            }
                                        }
                                    ]
                                }
                            }
                        ]
                    }
                }
            ]
        }
    }
}

```

actually equals to:

```auto
{
    "query":{
        "bool":{
            "must":[
                {
                    "multi_match":{
                        "fields":[
                            "*"
                        ],
                        "query":"kid",
                        "type":"best_fields"
                    }
                }
            ]
        }
    }
}

```

So, will Elasticsearch itself handle this situation? If not, should I simplify it or not, considering query performance.  
Thanks

---

<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 6, 2021, 6:07am UTC](https://discuss.elastic.co/t/will-elasticsearch-optimize-dsl-query/288588/2 "2021-12-06T06:07:36Z")

</div>

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