Search returning only hits with complete word match

(Mick Byrne) #1


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?


(David Pilato) #2

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


(Bdharrington7) #3

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

(Mick Byrne) #4

I am trying to use this:

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

curl -XPUT "" -d
   "settings": {
      "analysis": {
         "filter": {
            "nGram_filter": {
               "type": "nGram",
               "min_gram": 2,
               "max_gram": 20,
               "token_chars": [
         "analyzer": {
            "nGram_analyzer": {
               "type": "custom",
               "tokenizer": "whitespace",
               "filter": [
            "whitespace_analyzer": {
               "type": "custom",
               "tokenizer": "whitespace",
               "filter": [

"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 Byrne) #6

Got it working!

The Pizza Hut Pickle

(system) #7