# Search returning only hits with complete word match

**URL:** <https://discuss.elastic.co/t/search-returning-only-hits-with-complete-word-match/41293>\
**Category:** Elasticsearch\
**Created:** [February 9, 2016, 3:34pm UTC](https://discuss.elastic.co/t/search-returning-only-hits-with-complete-word-match/41293 "2016-02-09T15:34:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![phpMick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/phpmick/32/7683_2.png) [@phpMick](https://discuss.elastic.co/u/phpMick)\
**Post date:** [February 9, 2016, 3:34pm UTC](https://discuss.elastic.co/t/search-returning-only-hits-with-complete-word-match/41293/1 "2016-02-09T15:34:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 9, 2016, 4:55pm UTC](https://discuss.elastic.co/t/search-returning-only-hits-with-complete-word-match/41293/2 "2016-02-09T16:55:19Z")

</div>

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

HTH

---

<div class="post-metadata">

**Author:** ![bdharrington7](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bdharrington7/32/5515_2.png) [@bdharrington7](https://discuss.elastic.co/u/bdharrington7)\
**Post date:** [February 9, 2016, 7:10pm UTC](https://discuss.elastic.co/t/search-returning-only-hits-with-complete-word-match/41293/3 "2016-02-09T19:10:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![phpMick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/phpmick/32/7683_2.png) [@phpMick](https://discuss.elastic.co/u/phpMick)\
**Post date:** [February 10, 2016, 8:41am UTC](https://discuss.elastic.co/t/search-returning-only-hits-with-complete-word-match/41293/4 "2016-02-10T08:41:49Z")

</div>

I am trying to use this: [https://qbox.io/blog/multi-field-partial-word-autocomplete-in-elasticsearch-using-ngrams](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.

```auto
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",
            }
            }
            }
            }
            }'

```

---

<div class="post-metadata">

**Author:** ![phpMick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/phpmick/32/7683_2.png) [@phpMick](https://discuss.elastic.co/u/phpMick)\
**Post date:** [February 10, 2016, 9:45am UTC](https://discuss.elastic.co/t/search-returning-only-hits-with-complete-word-match/41293/5 "2016-02-10T09:45:37Z")

</div>

It looks like it works now, I swapped this "index\_analyzer" for "analyzer"

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

```auto
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
```

---

<div class="post-metadata">

**Author:** ![phpMick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/phpmick/32/7683_2.png) [@phpMick](https://discuss.elastic.co/u/phpMick)\
**Post date:** [February 12, 2016, 10:25am UTC](https://discuss.elastic.co/t/search-returning-only-hits-with-complete-word-match/41293/6 "2016-02-12T10:25:42Z")

</div>

Got it working!

[The Pizza Hut Pickle](http://artisantinkerer.github.io/2016/02/12/pizza-hut-pickle.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:16pm UTC](https://discuss.elastic.co/t/search-returning-only-hits-with-complete-word-match/41293/7 "2017-07-05T23:16:55Z")

</div>


