I’ve got a problem that I’m not entirely sure I understand. I’ve got the following Elasticsearch query, written in PHP, with fuzziness matching hardcoded; this results in about an expected 1,500 search results.
private function phraseQuery(array $matchFields): array {
return [
'bool' => [
"minimum_should_match" => 1,
"should" => [
$this->multiMatch($matchFields),
[
'match' => [
'Title' => [
'query' => $this->searchTerm,
'fuzziness' => 'AUTO:4,8'
]
]
], [
'match' => [
'TransliteratedTitle' => [
'query' => $this->searchTerm,
'fuzziness' => 'AUTO:4,8'
]
]
]
]
]
];
}
When I replace the ‘match’ parts of my query to dynamically generate with a function I get 4 exact search results; Elasticsearch effectively seems to ignore the fuzziness queries. I have confirmed on PHP Playground that the queries are structurally exactly the same, but there appears to be a difference between the two queries. Does the PHP spread operator not work in this way?
private function fuss(array $matchFields): array {
$fuzziness = [];
foreach($matchFields as $field) {
$query = ['query' => $this->searchTerm , 'fuzziness' => 'AUTO:4,8'];
$match = [ $field => $query ];
$fuzziness[] = [ 'match' => $match ];
}
return $fuzziness;
}
private function phraseQuery(array $matchFields): array {
return [
'bool' => [
"minimum_should_match" => 1,
"should" => [
$this->multiMatch($matchFields),
...$this->fuss($matchFields),
]
]
];
}
Any help is much appreciated!
FYI: I’m using Elastic Cloud and PHP v8
I have tested my code on PHP playground to make sure the queries to Elasticsearch are structured in the exact same way. I have run both forms of query and one returns 4 results and the other nearly 1,500.