我的Elasticsearch查询是这样的:
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'
)
)
)
)
)
);
结果是这样的:
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'
)
)
.................................................................................................
)
)
);
我想过滤结果并获得'type'=>的结果'分支',我改变了那样的查询
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'
)
)
)
)
)
);
但这次搜索什么也没有回复。
array(
'took' => 2,
'timed_out' => false,
'_shards' => array(
'total' => 5,
'successful' => 5,
'failed' => 0
),
'hits' => array(
'total' => 0,
'max_score' => NULL,
'hits' => array()
)
);
我认为查询是对的,但不知道为什么它没有得到任何结果。
映射
array(
'myindex' => array(
'mappings' => array(
'myindextype' => array(
'properties' => array(
'index' => array(
'type' => 'string'
),
'indexId' => array(
'type' => 'string'
),
'objId' => array(
'type' => 'string'
),
'title' => array(
'type' => 'string'
),
'type' => array(
'type' => 'string'
)
)
)
)
)
)
答案 0 :(得分:1)
我自己找到了答案。搜索查询必须像那样
POST _search
{
"query": {
"bool" : {
"must" : {
"query_string" :{
"query":"atm*",
"default_operator":"AND",
"minimum_should_match":"80%",
"default_field":"index"
}
},
"filter": {
"term": {
"type.keyword": "Branch"
}
}
}
}
}
现在一切都很好。