# Use of filtered query?

**URL:** https://discuss.elastic.co/t/use-of-filtered-query/75376
**Category:** Elasticsearch
**Created:** [February 16, 2017, 5:11pm UTC](https://discuss.elastic.co/t/use-of-filtered-query/75376 "2017-02-16T17:11:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Yaswanth](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@Yaswanth](https://discuss.elastic.co/u/Yaswanth)
#### Post date: [February 16, 2017, 5:11pm UTC](https://discuss.elastic.co/t/use-of-filtered-query/75376/1 "2017-02-16T17:11:22Z")

</div>

Hi,

I went through following query

```
{
  "filtered": {
    "query": {
      "match": { "tweet": "full text search" }
    },
    "filter": {
      "range": { "created": { "gte": "now-1d/d" }}
    }
  }
} 

```

The filtered query is used to filter the result set .

In the above query,after finding the yesterday's documents the filtered query is used to get the documents that match the particular field(i.e.tweet).

Correct me if my understanding is wrong.

Thanks..

---

<div class="post-metadata">

### Author: ![Yaswanth](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@Yaswanth](https://discuss.elastic.co/u/Yaswanth)
#### Post date: [February 24, 2017, 5:58am UTC](https://discuss.elastic.co/t/use-of-filtered-query/75376/2 "2017-02-24T05:58:15Z")

</div>

Since this is a post\_filter after match query the filter works ..

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [February 27, 2017, 8:31am UTC](https://discuss.elastic.co/t/use-of-filtered-query/75376/3 "2017-02-27T08:31:48Z")

</div>

Hey,

a post filter is applied after the search is executed, so it only makes sense to filter out documents there, not to execute another query, because the post filter does not apply scoring - this part needs to go into your regular query. See [https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-post-filter.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-post-filter.html)

Unless you are using aggregrations, there is no need for the post filter.

--Alex

---

<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: [March 27, 2017, 8:32am UTC](https://discuss.elastic.co/t/use-of-filtered-query/75376/4 "2017-03-27T08:32:10Z")

</div>

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