Im trying to create an autocomplete, this is my index creation:
curl -X PUT "localhost:9200/backoffice_clients-com" -H 'Content-Type: application/json' -d'
{
"settings": {
"analysis": {
"analyzer": {
"default": {
"type": "custom",
"tokenizer": "standard",
"filter": ["lowercase", "asciifolding"]
}
}
}
},
"mappings": {
"_doc": {
"properties": {
"id": { "type": "keyword" },
"backofficeclinic_id": { "type": "keyword" },
"fullname": { "type": "text" },
"email": { "type": "text" },
"idCard": { "type": "text" },
"telephone": { "type": "text" }
}
}
}
}'
and this is my search method
public function search(string $backofficeclinic_id, string $query): array
{
$params = [
'index' => 'backoffice_clients-com',
'body' => [
'query' => [
'bool' => [
'must' => [
['term' => ['backofficeclinic_id' => $backofficeclinic_id]],
[
'multi_match' => [
'query' => $query,
'type' => 'phrase_prefix',
'fields' => ['fullname', 'email', 'idCard', 'telephone']
]
]
]
]
],
'sort' => [
['_score' => ['order' => 'desc']],
],
'explain' => true, // Add explanation of the scoring
]
];
$response = $this->ESclient->search($params);
foreach ($response['hits']['hits'] as $hit) {
echo 'Document ID: ', $hit['_id'], PHP_EOL;
echo 'Score: ', $hit['_score'], PHP_EOL;
echo 'Explanation: ', json_encode($hit['_explanation']), PHP_EOL;
echo 'Source: ', json_encode($hit['_source']), PHP_EOL;
}
return array_map(function ($hit) {
return $hit['_source'];
}, $response['hits']['hits']);
}
Im trying with these 2 documents:
array:2 [
0 => array:6 [
"id" => "be7dcc65-1876-4bc1-9a01-dc9183d79e1d"
"backofficeclinic_id" => "dcf02d56-5240-43fb-9ba0-1ac3eafafa79"
"fullname" => "Mikel Good"
"email" => "mikel@gmail.com"
"idCard" => null
"telephone" => "+34661422181"
]
1 => array:6 [
"id" => "816c7cc6-965c-446b-b20f-8f1218757d73"
"backofficeclinic_id" => "dcf02d56-5240-43fb-9ba0-1ac3eafafa79"
"fullname" => "Mikel Bad"
"email" => "mikel@gmail.com"
"idCard" => "7777"
"telephone" => "+34661422182"
]
If I use these keywords:
"mikel" returns 2 documents
"mikel g" return 1 document (be7dcc65-1876-4bc1-9a01-dc9183d79e1d)
"mikel b" return 1 document (816c7cc6-965c-446b-b20f-8f1218757d73)
the problem occur when I try to find by using telephone, if I use "661" as keyword, 0 docs are being returned and it should return 2 documents..., I don't know what is need to be changed to fix my code.
Thank you very much for your time.
Th