json - Filter on multi match ES PHP
Solution:
The multi_match
query must be located inside bool/must
:
public function search_data_into_index($array)
{
$params = [
'index' => 'skills',
'type' => 'people',
'body' => [
'query' => [
'bool' => [
'must' => [
'multi_match' => [
'query' => 'react',
'fields' => [$array[2]],
'fuzziness' => 'AUTO',
]
],
'filter' => [
'geo_distance' => [
'distance' => '300m',
'location' => '-25, -49'
]
]
]
]
]
];
$response = $this->client->search($params);
print_r($response);
}
Answer
Solution:
You need to combine multiple queries using boolean query
In JSON format your query will look like
{
"query": {
"bool": {
"must": {
"multi_match": {
"query": "react",
"fields": [$array[2]]
}
},
"filter": {
"geo_distance": {
"distance": "300m",
"location": [
"-25, -49"
]
}
}
}
}
}
Source