Search returning only hits with complete word match


(Mick Byrne) #1

Hi,

I am new to Elastic, using Laravel and AWS.

I am trying to use Elastic Search in a Twitter Typeahead. I have built my index and searches are working but they only return matches for the complete word.

Eg: searching for ON

Will not return ???ON??
Will return THIS IS ON

What is the simplest way to do this? I want it to work like the search box on Wikipedia.

I have been looking a Completion Suggesters, am I on the right track?

Mick


(David Pilato) #2

You can use suggesters or you can change your mapping and use ngrams or edge ngrams.

HTH


(Bdharrington7) #3

What type of anayzers are you using for indexing and searching?


(Mick Byrne) #4

I am trying to use this: https://qbox.io/blog/multi-field-partial-word-autocomplete-in-elasticsearch-using-ngrams

This is what I am trying at the moment, parts is my index.

curl -XPUT "http://something.com:9200/parts" -d
'
{
   "settings": {
      "analysis": {
         "filter": {
            "nGram_filter": {
               "type": "nGram",
               "min_gram": 2,
               "max_gram": 20,
               "token_chars": [
                  "letter",
                  "digit",
                  "punctuation",
                  "symbol"
               ]
            }
         },
         "analyzer": {
            "nGram_analyzer": {
               "type": "custom",
               "tokenizer": "whitespace",
               "filter": [
                  "lowercase",
                  "asciifolding",
                  "nGram_filter"
               ]
            },
            "whitespace_analyzer": {
               "type": "custom",
               "tokenizer": "whitespace",
               "filter": [
                  "lowercase",
                  "asciifolding"
               ]
            }
         }
      }
   },

"mappings": {
      "parts": {
         "_all": {
            "index_analyzer": "nGram_analyzer",
            "search_analyzer": "whitespace_analyzer"
         },
         "properties": {
            "PART_NO": {
               "type": "string",
               "index": "no",
            }
            }
            }
            }
            }'

(Mick Byrne) #5

It looks like it works now, I swapped this "index_analyzer" for "analyzer"

I query like this:```
curl -XPOST "http://blahblah:9200/parts/_search" -d '{"size": 10,"query": {"match": {"_all": {"query": "bel"}}}}'

Does that look OK?

Now I have another problem.

I have some product codes in the format WH  CP100 and I want my typeahead to match these if the user types WH  CP100 or WHCP100.

So, I have spaces in my product code and I want the user to be able to type the product code with or without the spaces.

Is that possible?

Mick

(Mick Byrne) #6

Got it working!

The Pizza Hut Pickle


(system) #7