我正在使用弹性搜索2.2.0,我是新手。我想使用两个过滤器搜索结果,但它显示了致命错误:查询不支持多个字段。
两个过滤器是:
plocation: china
pcategoryid: 0,20,21
这是我的代码:
$search = 'Doors';
$limit = 6;
$params = [
'index' => 'product',
'body' => [
'query' => [
"bool" => [
"should" => [
'multi_match' => [
"fields" => [
"pname",
"pmodel",
"pcategoryname",
"pmetakeyword"
],
"query" => $search,
"type" => "phrase",
"boost" => 10
],
'multi_match' => [
"fields" => [
"pname",
"pmodel",
"pcategoryname",
"pmetakeyword"
],
"query" => $search,
"type" => "most_fields",
"fuzziness" => "1",
"boost" => 0
]
]
],
],
"filter" => [
"bool" => [
"must" => [
"term" => [
"ptypeid" => 1
]
],
"should" => [
"term" => [
"psearchstatus" => 1
]
],
"filter" => [
"terms" => [
"plocation" => ['china'], "pcategoryid" => [0,20,21]
]
]
],
],
"from" => ($page - 1) * $limit,
"size" => $limit
],
];
$client = Elasticsearch\ClientBuilder::create()->build();
$response = $client->search($params);
$results = $response['hits']['hits'];
还有另一种方法可以解决我正在尝试做什么,或者我是否在正确的轨道上?
答案 0 :(得分:-1)
问题是您尝试申请的terms
filter。与上面的term
过滤器一样,它只接受一个字段,但带有一组值。
"terms" => [
"plocation" => ['china'], "pcategoryid" => [0,20,21]
]
应该是
"terms" => [
"plocation" => ['china']
],
"terms" => [
"pcategoryid" => [0,20,21]
]