# NGRAM Tokens and query\_string question

**URL:** <https://discuss.elastic.co/t/ngram-tokens-and-query-string-question/80341>\
**Category:** Elasticsearch\
**Created:** [March 28, 2017, 5:57pm UTC](https://discuss.elastic.co/t/ngram-tokens-and-query-string-question/80341 "2017-03-28T17:57:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam\_Whittaker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adam_whittaker/32/75325_2.png) [@Adam\_Whittaker](https://discuss.elastic.co/u/Adam_Whittaker)\
**Post date:** [March 28, 2017, 5:57pm UTC](https://discuss.elastic.co/t/ngram-tokens-and-query-string-question/80341/1 "2017-03-28T17:57:52Z")

</div>

If i have a field that is NGRAM tokenized and i do a query\_string query does the search RANK the full word match over partial matches?

Example:

i search "test"  
and i get the following docs:

my test document  
my testing document  
my tested document

test is matched to all 3 but will the first "my test document" be RANKED (scored) higher than the others since its a full word match?

Thanks,

---

<div class="post-metadata">

**Author:** ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)\
**Post date:** [March 28, 2017, 11:00pm UTC](https://discuss.elastic.co/t/ngram-tokens-and-query-string-question/80341/2 "2017-03-28T23:00:13Z")

</div>

> test is matched to all 3 but will the first "my test document" be RANKED (scored) higher than the others since its a full word match?

No, if you want that, I would recommend that you analyze the text multiple ways by using a multi field (see: [fields | Elasticsearch Guide [5.3] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/multi-fields.html)) so you can match both your ngram and regular analyzed text. Then at query time you can query both within a bool query so both "should" clauses matching will make the score higher of the document you want to have a higher score.

---

<div class="post-metadata">

**Author:** ![Adam\_Whittaker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adam_whittaker/32/75325_2.png) [@Adam\_Whittaker](https://discuss.elastic.co/u/Adam_Whittaker)\
**Post date:** [April 6, 2017, 3:01pm UTC](https://discuss.elastic.co/t/ngram-tokens-and-query-string-question/80341/3 "2017-04-06T15:01:24Z")

</div>

OK thanks for your help. It works well

---

<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:** [May 4, 2017, 3:01pm UTC](https://discuss.elastic.co/t/ngram-tokens-and-query-string-question/80341/4 "2017-05-04T15:01:26Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
