elasticsearch,Php,elasticsearch" /> elasticsearch,Php,elasticsearch" />

Php 多术语筛选器不适用于弹性搜索

Php 多术语筛选器不适用于弹性搜索,php,elasticsearch,Php,elasticsearch,我使用的是elastic search 2.2.0,我是这方面的新手。我想使用两个过滤器搜索结果,但它显示了一个致命错误:查询不支持多个字段 两个过滤器是: plocation: china pcategoryid: 0,20,21 这是我的密码: $search = 'Doors'; $limit = 6; $params = [ 'index' => 'product', 'body' => [ 'query' => [

我使用的是elastic search 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'];
是否有其他方法可以实现我正在尝试的目标,或者我是否走上了正确的轨道?

问题在于您正在尝试应用的目标。与上面的
术语
过滤器类似,它只接受单个字段,但包含一个值数组

"terms" => [
  "plocation" => ['china'], "pcategoryid" => [0,20,21]
]
应该是

"terms" => [
  "plocation" => ['china']
],
"terms" => [
  "pcategoryid" => [0,20,21]
]

请同时提供索引/类型的结构不知道为什么会被否决,但这就是问题所在。