Hi, i have the follow problem. In my elasticsearch index i have names like Festmacher,Festmacher - Emden,Festmacher - Bremerhaven,Festmacher - Hamburg,Festmacher - Bremen,Festmacher - Glückstad,Festmacher - Brunsbüttel etc. I use the match_phrase query search. If i enter FEstmacher i found all names. If i enter fest i found nothing. Is there a way to make "like" search or "wildcard usage"? It would be great that when i enter "fest brem" i got all names back with these 2 words. Thanks for helping.
You can look at ngrams and adapt your mapping / analysis chain to meet your requirements.
Hi, thanks for replay. I try it but dont get it to work right. I read the manual but there are some questions open. I want the ngram tokenizer only for one index type. Not for all types in my index. Is this possible? Do i have to create the index with the analyze settings first and then index or could i change the settings latter with putSettings? Because there i got error, could not change no dynmaic settings.
I think i have to read more the manual. But some hint would be great.
Thanks a lot.
Okay, i come closer to my wishes.
My analysis settings looks like this:
'analysis' => [
'analyzer' => [
'apps_search' => [
'type' => 'custom',
'tokenizer' => 'keyword',
'filter' => ['lowercase','substring']
],
'apps_index' => [
'type' => 'custom',
'tokenizer' => 'keyword',
'filter' => ['lowercase','substring']
]
],
'filter' => [
'substring' => [
'type' => 'nGram',
'min_gram' => '1',
'max_gram' => '20',
#'token_chars' => ['letter', 'digit', 'whitespace']
]
]
]
And my mapping looks like:
'mappings' => [
'subcategory' => [
'properties' => [
'name' => [
'type' => 'string',
#'index' => 'analyzed',
'analyzer' => 'apps_index',
'search_analyzer' => 'apps_search'
]
]
]
]
But when i know use a match_phrase query like:
'query' => [
'match_phrase' => [
'name' => 'Festmacher'
]
]
the search return all names. Not only ones including "Festmacher".
The next thing is: I need to look for word phrases. If i enter "fest brem" the search should return all names like "FEstmacher Bremen" , "Festmacher Bremerhaven" and so on. How could i make this happen?
Thanks Stefan
I try all search queries but without luck. What do i not see? There must be a little thing wrong. Why the search retuns all indexed names?
The problem is that you are applying a ngram to what the user is entering.
So when you search for fest
after analysis, it becomes f
, fe
, fes
, fest
.
I guess that f
matches a lot of docs.
I'd use a simple
search_analyzer.
Thanks for Reply. Sounds logical. Only one questions left.. How Can i set an Index Analyser in my Mapping . I dont found Something. Search Analyser is there but Index Analyser not .