# Query inside a filter?

**URL:** <https://discuss.elastic.co/t/query-inside-a-filter/45185>\
**Category:** Elasticsearch\
**Created:** [March 23, 2016, 6:43am UTC](https://discuss.elastic.co/t/query-inside-a-filter/45185 "2016-03-23T06:43:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vicente\_de\_Rivera\_II](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@Vicente\_de\_Rivera\_II](https://discuss.elastic.co/u/Vicente_de_Rivera_II)\
**Post date:** [March 23, 2016, 6:43am UTC](https://discuss.elastic.co/t/query-inside-a-filter/45185/1 "2016-03-23T06:43:31Z")

</div>

Below is the json passed into elasticsearch js client.

1. Is the `query_string` treated as query here? How do I declare it as a filter?
2. How come this works given that my top element is `filter`?

```auto
    {
      "index": "index",
      "sort": [
        "shop.chaosEquiv:asc"
      ],
      "from": 0,
      "size": 50,
      "body": {
        "filter": {
          "query": {
            "query_string": {
              "default_operator": "AND",
              "query": "info.name:\"Sire of Shards\" attributes.league:\"Perandus\" shop.hasPrice:true shop.verified:YES"
            }
          }
        }
      }
    }

```

---

<div class="post-metadata">

**Author:** ![Vicente\_de\_Rivera\_II](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@Vicente\_de\_Rivera\_II](https://discuss.elastic.co/u/Vicente_de_Rivera_II)\
**Post date:** [March 24, 2016, 8:51am UTC](https://discuss.elastic.co/t/query-inside-a-filter/45185/2 "2016-03-24T08:51:37Z")

</div>

Ended up with:

```auto
  "body": {
    "query": {
      "filtered": {
        "filter": {
          "bool": {
            "must": {
              "query_string": {
                "default_operator": "AND",
                "query": "attributes.itemType:Boots modsPseudo.+#%\\ Total\\ to\\ Fire\\ Resistance:[40 TO *] attributes.league:\"Perandus\" shop.hasPrice:true shop.verified:YES"
              }
            }
          }
        }
      }
    }
  }

```

---

<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:** [July 5, 2017, 11:05pm UTC](https://discuss.elastic.co/t/query-inside-a-filter/45185/3 "2017-07-05T23:05:36Z")

</div>


