声明:我使用的elasticsearch的版本是5.4.0,具体参考下面的链接
https://www.elastic.co/guide/en/elasticsearch/reference/5.4/query-dsl-filtered-query.html
filtered 查询已经被bool 查询取代了,
bool查询:
https://www.elastic.co/guide/en/elasticsearch/reference/5.4/query-dsl-bool-query.html
对应的PHP查询的body如下:
1 // 带过滤的查询语句,过滤where furniture_type_id = 1 and apt_id = 1266 2 $params = [ 3 'index' => 'dpjia', 4 'type' => 'apartment', 5 'size' => 100, 6 'body' => [ 7 'query' => [ 8 'bool' => [ 9 'must' => [ 10 'match' => [ 11 'apt_name' => '户型' 12 ] 13 ], 14 //filter 相当于 SQL 里的where条件 where furniture_type_id = 1 and apt_id = 1266 15 'filter' => [ 16 [ 17 'term' => [ 18 'furniture_type_id' => 1 19 ] 20 ], 21 [ 22 'term' => [ 23 'apt_id' => 1266 24 ] 25 ] 26 ] 27 ], 28 ] 29 ] 30 ]; 31 32 33 $response = self::$client->search($params); 34 print_r($response);