尝试在Elasticsearch中使用PHP客户端进行查询,并优先考虑部分单词匹配但仍包含模糊匹配。如果我删除address.company匹配块,查询将按预期工作,但无论我如何构建它,它都会被打破。我在格式化上迷失了还包括优先级较低的模糊搜索?
$search_data = [
"from" => (int) $start, "size" => (int) $count,
'query' => [
'bool' => [
'filter' => [
['term' => ['active' => 1]],
['term' => ['type' => 2]],
],
'must' => [
'wildcard' => [
'address.company' => '*' . $search_query . '*'
],
'match' => [
'address.company' => [
'query' => $search_query,
'operator' => 'and',
'fuzziness' => 'AUTO',
],
],
],
],
],
];
答案 0 :(得分:0)
虽然我可能很明显是ES的新手,但这个解决方案似乎得到了我追求的数据。我只提到这一点,因为如果有人在将来看到这个,可能会有更理想的方式。从必须切换到应该并且有点不同地包装数组就行了。
$search_data = [
"from" => (int) $start, "size" => (int) $count,
'query' => [
'bool' => [
'filter' => [
['term' => ['active' => 1]],
['term' => ['type' => 2]],
],
'should' => [
[
'match' => ['address.company' => ['query'=>$search_query,'boost'=>10]],
],
[
'match' =>
[
'address.company' =>
[
'query' => $search_query,
'fuzziness' => 'AUTO',
],
],
],
],
'minimum_should_match'=>1,
],
],
];