# Partial word matching with query\_string and edge ngrams

**URL:** <https://discuss.elastic.co/t/partial-word-matching-with-query-string-and-edge-ngrams/9026>\
**Category:** Elasticsearch\
**Created:** [September 14, 2012, 7:23pm UTC](https://discuss.elastic.co/t/partial-word-matching-with-query-string-and-edge-ngrams/9026 "2012-09-14T19:23:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jim\_Mitchener](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jim_mitchener/32/2981_2.png) [@Jim\_Mitchener](https://discuss.elastic.co/u/Jim_Mitchener)\
**Post date:** [September 14, 2012, 7:23pm UTC](https://discuss.elastic.co/t/partial-word-matching-with-query-string-and-edge-ngrams/9026/1 "2012-09-14T19:23:29Z")

</div>

We are implementing live filtering of a list via elasticsearch. In order to  
have the filters be live on every keystroke we need to match partial words.  
I'd like to do this with ngrams to speed up queries.

I can't seem to be able to get any matches to work without using wildcards.  
I'm not even sure where I should be creating the ngrams. Should they be  
done in a filter? Is this even meant to be done on mutli-word description  
fields?

Here is a gist of what I'm currently attempting

> <https://gist.github.com/jmitchener/3724082>

Any help would be greatly appreciated. Thanks!

--

---

<div class="post-metadata">

**Author:** ![BillyEm](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@BillyEm](https://discuss.elastic.co/u/BillyEm)\
**Post date:** [September 15, 2012, 3:47am UTC](https://discuss.elastic.co/t/partial-word-matching-with-query-string-and-edge-ngrams/9026/2 "2012-09-15T03:47:06Z")

</div>

not sure if the dsl has preserved the behavior of it: try adding explain  
to your working query; its in the guide. You'll get a quick view of some of  
what's actually in the dictionary.

On Friday, September 14, 2012 3:23:29 PM UTC-4, Jim Mitchener wrote:

> We are implementing live filtering of a list via elasticsearch. In order  
> to have the filters be live on every keystroke we need to match partial  
> words. I'd like to do this with ngrams to speed up queries.
> 
> I can't seem to be able to get any matches to work without using  
> wildcards. I'm not even sure where I should be creating the ngrams. Should  
> they be done in a filter? Is this even meant to be done on mutli-word  
> description fields?
> 
> Here is a gist of what I'm currently attempting  
> [edgengram\_test.sh · GitHub](https://gist.github.com/3724082)
> 
> Any help would be greatly appreciated. Thanks!

--

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [September 17, 2012, 9:11am UTC](https://discuss.elastic.co/t/partial-word-matching-with-query-string-and-edge-ngrams/9026/3 "2012-09-17T09:11:17Z")

</div>

Hi Jim

> I can't seem to be able to get any matches to work without using  
> wildcards. I'm not even sure where I should be creating the ngrams.  
> Should they be done in a filter? Is this even meant to be done on  
> mutli-word description fields?

You are using the edge-ngrams on the label and description fields, but  
then you are searching on the \_all field (which is the default if no  
field is specified).

Try this instead:

curl -XGET '[http://localhost:9200/ngramtest/footype/\_search?pretty](http://localhost:9200/ngramtest/footype/_search?pretty)' -d '  
{  
"query" : {  
"query\_string" : {  
"query" : "alask",  
"fields" : ["label", "description"]  
}  
}  
}'

clint

--

---

<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 6, 2017, 3:12am UTC](https://discuss.elastic.co/t/partial-word-matching-with-query-string-and-edge-ngrams/9026/4 "2017-07-06T03:12:36Z")

</div>


