What search to use?


(Stefan Kruse-2) #1

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.


(David Pilato) #2

You can look at ngrams and adapt your mapping / analysis chain to meet your requirements.


(Stefan Kruse-2) #3

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.


(Stefan Kruse-2) #4

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


(Stefan Kruse-2) #5

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?


(David Pilato) #6

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.


(Stefan Kruse-2) #7

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 .


(system) #8