# Can't filter search result

**URL:** <https://discuss.elastic.co/t/cant-filter-search-result/75442>\
**Category:** Elasticsearch\
**Created:** [February 17, 2017, 7:23am UTC](https://discuss.elastic.co/t/cant-filter-search-result/75442 "2017-02-17T07:23:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nagiyevel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nagiyevel/32/15541_2.png) [@nagiyevel](https://discuss.elastic.co/u/nagiyevel)\
**Post date:** [February 17, 2017, 7:23am UTC](https://discuss.elastic.co/t/cant-filter-search-result/75442/1 "2017-02-17T07:23:07Z")

</div>

My Elasticsearch query is like that:

```
array(
    'index' => 'myindex',
    'type' => 'myindextype',
    'from' => 0,
    'size' => 500,
    'body' => array(
        'query' => array(
            'filtered' => array(
                'filter' => NULL,
                'query' => array(
                    'query_string' => array(
                        'default_operator' => 'AND',
                        'query' => 'atm*',
                        'minimum_should_match' => '80%',
                        'default_field' => 'index'
                    )
                )
            )
        )
    )
);

```

Result is like that:

```
array(
    'took' => 6,
    'timed_out' => false,
    '_shards' => array(
        'total' => 5,
        'successful' => 5,
        'failed' => 0
    ),
    'hits' => array(
        'total' => 492,
        'max_score' => 1,
        'hits' => array(
            0 => array(
                '_index' => 'myindex',
                '_type' => 'myindextype',
                '_id' => 'Branch-571',
                '_score' => 1,
                '_source' => array(
                    'indexId' => 'Branch-571',
                    'objId' => '571',
                    'index' => 'atm Baki CNaxcivanski lisey Baki sheh Zig shossesi Admiral Naximov kuc 1 ',
                    'type' => 'Branch',
                    'title' => 'Bakı C.Naxçıvanski lisey'
                )
            ),
            .................................................................................................
            196 => array(
                '_index' => 'myindex',
                '_type' => 'myindextype',
                '_id' => 'Page-114',
                '_score' => 1,
                '_source' => array(
                    'indexId' => 'Page-114',
                    'objId' => 'Page-114',
                    'index' => 'atm Baki CNaxcivanski lisey Baki sheh Zig shossesi Admiral Naximov kuc 1 ',
                    'type' => 'Page',
                    'title' => 'Kreditlər'
                )
            )
            .................................................................................................
        )
    )
);

```

I want to filter result and get results where 'type' =\> 'Branch' and I change query like that

```
array(
    'index' => 'myindex',
    'type' => 'myindextype',
    'from' => 0,
    'size' => 10,
    'body' => array(
        'query' => array(
            'filtered' => array(
                'filter' => array(
                    'bool' => array(
                        'must' => array(
                            'term' => array(
                                'type' => 'Branch'
                            )
                        )
                    )
                ),
                'query' => array(
                    'query_string' => array(
                        'default_operator' => 'AND',
                        'query' => 'atm*',
                        'minimum_should_match' => '80%',
                        'default_field' => 'index'
                    )
                )
            )
        )
    )
);

```

But this search return nothing.

```
array(
    'took' => 2,
    'timed_out' => false,
    '_shards' => array(
        'total' => 5,
        'successful' => 5,
        'failed' => 0
    ),
    'hits' => array(
        'total' => 0,
        'max_score' => NULL,
        'hits' => array()
    )
);

```

I think query is right but no idea why it didn't get any result.

---

<div class="post-metadata">

**Author:** ![nagiyevel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nagiyevel/32/15541_2.png) [@nagiyevel](https://discuss.elastic.co/u/nagiyevel)\
**Post date:** [March 6, 2017, 10:35am UTC](https://discuss.elastic.co/t/cant-filter-search-result/75442/2 "2017-03-06T10:35:46Z")

</div>

I have find answer myself. The search query must be like that

```
POST _search
{
  "query": {
    "bool" : {
      "must" : {
        "query_string" :{
          "query":"atm*",
          "default_operator":"AND",
          "minimum_should_match":"80%",
          "default_field":"index"
        }
      },
      "filter": {
        "term": {
          "type.keyword": "Branch"
        }
      }
    }
  }
}

```

All is working good now.

---

<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:** [April 3, 2017, 10:36am UTC](https://discuss.elastic.co/t/cant-filter-search-result/75442/3 "2017-04-03T10:36:03Z")

</div>

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