Elasticsearch - How to decide the best mapping scheme?

I'm super new to Elasticsearch and have been finding my way to make search work for the upcoming version of CrazyEngineers. I wish to know from our fellow CEans who've worked with ES - how to decide which mapping scheme is most suitable? By mapping scheme, I'm referring to the analyzers and tokenizers that we need to define at the time of indexing documents.

I'm specifically interested in n-gram tokenizers but haven't been getting desired results for search terms. Would appreciate pointers.

Replies

  • Saandeep Sreerambatla
    Saandeep Sreerambatla
    what is the type of data that you are working on ? We need information on the business case?
    I didnt work on ES at all, but my team works on ES so much. So need more information on this so that i can go back and get the answers.
  • Kaustubh Katdare
    Kaustubh Katdare
    Thanks, #-Link-Snipped-# . Since posting the thread, I've learned more about ES. Right now, I'm in the 'fine-tuning' phase for @mention suggestions.

    Let's say a user starts typing a name. Ideally, we should return multiple matches that have the starting characters, but these matches have to be relevant. I'm therefor experimenting with 'edge-ngram' tokenizer.

    Here's the query I posted on a forum -

    Here's how my current settings look like -

    protected $settings = [
       'analysis'  => [
           'filter'    =>  [
               'autocomplete_filter'   =>  [
                   'type'  =>  'edge_ngram',
                   'min_gram'  =>  2,
                   'max_gram'  =>  12,
               ],
           ],
           'analyzer'  =>  [
               'autocomplete' =>  [
                   'type'  =>  'custom',
                   'tokenizer' =>  'standard',
                   'filter'    =>  ['lowercase', 'autocomplete_filter']
               ]
           ]
       ]
    ];
    
    and
    public function buildQueryPayload()
    {
       return [
           'must'  =>  [
               'multi_match'   =>  [
                   'query'     => $this->builder->query,
                   'fields'    => ['first_name', 'last_name', 'name^2'],
                   'type'      =>  'phrase_prefix'
               ]
           ]
       ];
    }
    
    This is my best try so far; but I'm not happy with the results. I've the following in my User model -

    public function toSearchableArray() {
       return [
           'first_name'    =>  $this->first_name,
           'last_name'     =>  $this->last_name,
           'name'          =>  $this->first_name . ' ' . $this->last_name
       ];
    }
    
    I'm thinking of adding an extra field from my database to the index called last_activity_at and then sort the suggested users according to those who've the most recent last_activity.

    Can someone suggest if I need to make changes to my filter, analyzer or the query? The end result I want to achieve is -

    User types: @Joh . The system should return
    1. 'John Doe' [most recently active]
    2. 'John Doe' [second most recently active]
    3. 'Johan Kent'
    4. 'Johar Woe'
    ... like that. If the last_activity_at field is null, ES should only match based upon the closest search.

    Would welcome suggestions.

You are reading an archived discussion.

Related Posts

We all know there's no easy way to get a job in electrical field, that too in a developing country like India. Let us discuss on valuable experiences and suggestions...
Beguiling, baffling or both—that’s blockchain. To clarify blockchain for the benefit of companies and other organizations, as well as engineers and managers, the National Institute of Standards and Technology (NIST)...
I have completed diploma in civil engineering can I apply for these post ???
Wikipedia - Florida International University pedestrian bridge collapse The Florida Department of Transport has released the engineering design and construction plans for the FIU pedestrian bridge, which can be downloaded...
Hiii guys!!! I am looking for a dedicated and hard-working study partner for my PE exams. I have uploaded my profile and study schedule on studypal. If anyone of you...