# Help needed in refactoring Elasticsearch Query

**URL:** <https://discuss.elastic.co/t/help-needed-in-refactoring-elasticsearch-query/245581>\
**Category:** Elasticsearch\
**Created:** [August 19, 2020, 10:23am UTC](https://discuss.elastic.co/t/help-needed-in-refactoring-elasticsearch-query/245581 "2020-08-19T10:23:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasad98](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prasad98/32/64837_2.png) [@prasad98](https://discuss.elastic.co/u/prasad98)\
**Post date:** [August 19, 2020, 10:23am UTC](https://discuss.elastic.co/t/help-needed-in-refactoring-elasticsearch-query/245581/1 "2020-08-19T10:23:41Z")

</div>

I am trying to refactor a elasticsearch query from written for 2.4 (it's a very old one) and want to make it compatible for elasticsearch 7.5

Here is my structured query:

```auto
{
'query': {
    'filtered': {
        'filter': {}, 
        'query': {
            'bool': {
                'must': [
                    {
                        'bool': {
                            'should': []
                        }
                    }
                ]
            }
       }
    }
}, 
'_source': {'exclude': []}, 'size': 0}

```

I have gone through the stackoverflow for alternative of `filtered` clause since it has been deprecated in new version. Most of the solutions on the internet are related to replacing `filtered` followed by `filter` clause to `bool` followed by `filter` clause.

In this case, I have `filtered` followed by `query` also. How should refactor the whole query in clean format ?

It would be great if anyone can help me with this, 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:** [September 16, 2020, 10:23am UTC](https://discuss.elastic.co/t/help-needed-in-refactoring-elasticsearch-query/245581/2 "2020-09-16T10:23:50Z")

</div>

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