# nGram Autocomplete

**URL:** <https://discuss.elastic.co/t/ngram-autocomplete/117072>\
**Category:** Elasticsearch\
**Created:** [January 25, 2018, 3:57pm UTC](https://discuss.elastic.co/t/ngram-autocomplete/117072 "2018-01-25T15:57:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hrachya\_Yeghishyan](https://avatars.discourse-cdn.com/v4/letter/h/a9a28c/32.png) [@Hrachya\_Yeghishyan](https://discuss.elastic.co/u/Hrachya_Yeghishyan)\
**Post date:** [January 25, 2018, 3:57pm UTC](https://discuss.elastic.co/t/ngram-autocomplete/117072/1 "2018-01-25T15:57:15Z")

</div>

I have implemented multifield partial autocomplete using nGram-s as presented in the following blogpost: [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)  
It works great in case of a single match query. However, it fails when using the same match query inside a boolean query which contains several other queries as well.  
Is there any way to gain the same result as a single match query provides in case of a boolean query?

For instance the match query below works as expected. It retrieves all those documents which contain both "shop" and "mi".

```
{
     "query": {
         "match" : {
            "_all": {
                 "query": "shop mi",
                 "operator": "and"
            }
         }
     }
 }

```

Whereas the boolean query below, which contains the same match query doesn't retrieve any documents. It results in 0 hits. However, it should also retrieve all those documents, which contain both "shop" and "mi", but having values for the "@timestamp" field in the specified range.

```
{
"query": {
  "bool" : {
    "must" : [
      {
        "range" : {
          "@timestamp" : {
            "from" : 1516881600000,
            "to" : 1516882500000,
            "include_lower" : true,
            "include_upper" : true,
            "format" : "epoch_millis",
            "boost" : 1.0
          }
        }
      }
    ],
    "filter" : [
      {
        "match" : {
          "_all" : {
            "query" : "shop mi",
            "operator" : "and",
            "boost" : 1.0
          }
        }
      }
    ],
    "boost" : 1.0
  }
 }
}
```

---

<div class="post-metadata">

**Author:** ![Hrachya\_Yeghishyan](https://avatars.discourse-cdn.com/v4/letter/h/a9a28c/32.png) [@Hrachya\_Yeghishyan](https://discuss.elastic.co/u/Hrachya_Yeghishyan)\
**Post date:** [January 29, 2018, 2:46pm UTC](https://discuss.elastic.co/t/ngram-autocomplete/117072/2 "2018-01-29T14:46:33Z")

</div>

Resolved: Actually there is no problem with the second query. It came out that there was no document that contained "shop mi" and had a value of "@timestamp" in the specified range. When changing the parameters of the range query properly, the boolean query does return a document containing "shop mi".

---

<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:** [February 26, 2018, 2:47pm UTC](https://discuss.elastic.co/t/ngram-autocomplete/117072/3 "2018-02-26T14:47:13Z")

</div>

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