Can't filter search result

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.

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.

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