# Filter Query Issue

**URL:** <https://discuss.elastic.co/t/filter-query-issue/76216>\
**Category:** Elasticsearch\
**Created:** [February 23, 2017, 12:30pm UTC](https://discuss.elastic.co/t/filter-query-issue/76216 "2017-02-23T12:30:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![N\_M\_10](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@N\_M\_10](https://discuss.elastic.co/u/N_M_10)\
**Post date:** [February 23, 2017, 12:30pm UTC](https://discuss.elastic.co/t/filter-query-issue/76216/1 "2017-02-23T12:30:34Z")

</div>

I am trying to achieve "AND" in filter .

Example: All those documents which has **"PL" AND "rall"** in there TAGS field.

Please let me know where I am wrong ?

My Query:

```
    {
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "should": [
            {
              "query_string": {
                "fields": [
                  "TITLE.title^5.5",
                  "TITLE.ngrams_front^2"
                ],
                "analyzer": "titles_default_analyzer",
                "query": "visa"
              }
            },
            {
              "fuzzy": {
                "TITLE.title": {
                  "value": "visa",
                  "boost": 2,
                  "max_expansions": 20,
                  "prefix_length": 0
                }
              }
            },
            {
              "query_string": {
                "fields": [
                  "SEARCHABLE.title^1.5",
                  "SEARCHABLE.ngrams_front^1"
                ],
                "analyzer": "titles_default_analyzer",
                "query": "visa"
              }
            },
            {
              "fuzzy": {
                "SEARCHABLE.title": {
                  "value": "visa",
                  "boost": 1,
                  "max_expansions": 20,
                  "prefix_length": 0
                }
              }
            },
            {
              "match_phrase_prefix": {
                "TITLE.title": {
                  "query": "visa",
                  "boost": 100
                }
              }
            }
          ],
          "filter": {
            "bool": {
              "must": [
                {
                  "terms": {
                    "TAGS": [
                      "PL"
                    ]
                  }
                },
                {
                  "terms": {
                    "TAGS": [
                      "rall"
                    ]
                  }
                }
              ]
            }
          }
        }
      },
      "field_value_factor": {
        "field": "BST_SCR_HGH",
        "modifier": "log"
      }
    }
  }
}
```

---

<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, 9:07am UTC](https://discuss.elastic.co/t/filter-query-issue/76216/2 "2017-02-27T09:07:53Z")

</div>

Hey,

you are running this filter inside of a `function_score` query, which basically means, that you want to apply the function only to such documents. If you want to filter out those documents, you have to put it outside of the function score query.

--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, 9:08am UTC](https://discuss.elastic.co/t/filter-query-issue/76216/3 "2017-03-27T09:08:02Z")

</div>

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