# Fuzzy, nGrams.. for incorrectly spelt phrases?

**URL:** <https://discuss.elastic.co/t/fuzzy-ngrams-for-incorrectly-spelt-phrases/27641>\
**Category:** Elasticsearch\
**Created:** [August 19, 2015, 6:28am UTC](https://discuss.elastic.co/t/fuzzy-ngrams-for-incorrectly-spelt-phrases/27641 "2015-08-19T06:28:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![squalli2008](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@squalli2008](https://discuss.elastic.co/u/squalli2008)\
**Post date:** [August 19, 2015, 6:28am UTC](https://discuss.elastic.co/t/fuzzy-ngrams-for-incorrectly-spelt-phrases/27641/1 "2015-08-19T06:28:35Z")

</div>

The documents I am looking for have titles of

"Old Book of History"  
"New Book of History"  
"The Book of Histories"

I would like to search for the following and find all documents but with "Old Book of History" at the top of the results:

old histry (i.e. simple spelling mistake on one of the words)  
bok old histry (i.e. spelling mistakes in 2 words and words in any order)

So far I have this working by mapping the title to a new title.titleNGram field and using an nGram analyzer for indexing and a snowball analyzer at search time.

In order to boost exact matches the query looks something like this:

```
  "query": {
    "bool" : {
    "should": [
        {
            "match": {
              "title": {
                "query": "history",
                "boost": 10
              }
            }
        },
        {
            "match": {
              "title.titleNGram": {
                "query": "history",
                "fuzziness": 2,
                "operator": "and",
                "prefix_length": 3,
                "analyzer" : "snowball"
              }
            }
        }
    ]
}

```

}

So my question is really... Is this the right way to be doing this?!

---

<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:55pm UTC](https://discuss.elastic.co/t/fuzzy-ngrams-for-incorrectly-spelt-phrases/27641/2 "2017-07-05T23:55:06Z")

</div>


