I am trying to setup search analysis in Elasticsearch to get as close as possible to the following scenario:
I have 4 users:
- Karolina Abc (karolinaabc@example.com)
- Karolina Def (karolinadef@example.com)
- Karol Abc (karolabc@example.com)
- Karol Adf (karoladf@example.com)
When I type:
"Kar"
I should get all 4 users.
When I type:
"Karol"
I still should get all 4 users.
When I type:
"Karol A"
I should get user no. 3 & 4.
When I type:
"Karol Ad"
I should get user no. 4 only.
So when I start typing it should start matching let's say first 3 chars for field firstName, lastName and emailAddress and for that I use MultiMatch. The result should narrow once I type more chars and in the end return only ones that matches my query string.
The problem is that when I type now "Karol Ad" it returns all 4 users because "Karol" matches "Karolina".
I have the following setup:
settings:
index:
analysis:
analyzer:
search_analyzer:
type: custom
tokenizer: standard
filter: [lowercase, edge_ngram]
filter:
edge_ngram:
type: edge_ngram
min_gram: 1
max_gram: 10
and
$boolQuery = new Query\BoolQuery();
$boolQuery->addMust((new Query\MultiMatch())
->setFields(['firstName', 'lastName', 'emailAddress'])
->setType(Query\MultiMatch::TYPE_CROSS_FIELDS)
->setQuery('Karol Ad')
->setOperator('and')
);
$query = new Query();
$query->setQuery($boolQuery);
$result = $this->finder->find($query);
Is there anyone that may know the solution to the problem I am facing?