# Tolerance spelling

**URL:** <https://discuss.elastic.co/t/tolerance-spelling/83028>\
**Category:** Elasticsearch\
**Created:** [April 20, 2017, 10:24am UTC](https://discuss.elastic.co/t/tolerance-spelling/83028 "2017-04-20T10:24:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maher\_Ben\_Taleb\_Ali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maher_ben_taleb_ali/32/26774_2.png) [@Maher\_Ben\_Taleb\_Ali](https://discuss.elastic.co/u/Maher_Ben_Taleb_Ali)\
**Post date:** [April 20, 2017, 10:24am UTC](https://discuss.elastic.co/t/tolerance-spelling/83028/1 "2017-04-20T10:24:18Z")

</div>

Hi,

I need help in optimizing the query to increase the number of matches without affecting the accuracy.  
What are the best options to tolerate some spelling mistakes?

Thank you.

---

<div class="post-metadata">

**Author:** ![geekpete](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/geekpete/32/20409_2.png) [@geekpete](https://discuss.elastic.co/u/geekpete)\
**Post date:** [May 4, 2017, 4:37am UTC](https://discuss.elastic.co/t/tolerance-spelling/83028/2 "2017-05-04T04:37:08Z")

</div>

Hi Maher,

One option might be to look at a fuzzy query:  
[https://www.elastic.co/guide/en/elasticsearch/reference/5.3/query-dsl-fuzzy-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/query-dsl-fuzzy-query.html)

```auto
POST /test-fuzz/fuzztype/
{
  "message": "this is a test"
}

POST /test-fuzz/fuzztype/
{
  "message": "this is a toast"
}

POST /test-fuzz/fuzztype/
{
  "message": "this is a testing time"
}

POST /test-fuzz/fuzztype/
{
  "message": "this is a tester"
}

GET test-fuzz/_search

GET test-fuzz/_search
{
  "query": {
    "match": {
      "message": "test"
    }
  }
}

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1.0126973,
    "hits": [
      {
        "_index": "test-fuzz",
        "_type": "fuzztype",
        "_id": "AVvRtnqQtT7Egp-Jj5Qk",
        "_score": 1.0126973,
        "_source": {
          "message": "this is a test"
        }
      }
    ]
  }
}

GET test-fuzz/_search
{
  "query": {
    "fuzzy": {
      "message": {
        "value": "test",
        "fuzziness": 2
      }
    }
  }
}

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 3,
    "max_score": 1.0126973,
    "hits": [
      {
        "_index": "test-fuzz",
        "_type": "fuzztype",
        "_id": "AVvRtnqQtT7Egp-Jj5Qk",
        "_score": 1.0126973,
        "_source": {
          "message": "this is a test"
        }
      },
      {
        "_index": "test-fuzz",
        "_type": "fuzztype",
        "_id": "AVvRtuobtT7Egp-Jj5VM",
        "_score": 0.50634867,
        "_source": {
          "message": "this is a toast"
        }
      },
      {
        "_index": "test-fuzz",
        "_type": "fuzztype",
        "_id": "AVvRtuzqtT7Egp-Jj5Wc",
        "_score": 0.14384104,
        "_source": {
          "message": "this is a tester"
        }
      }
    ]
  }
}

```

There's also the term suggester that might be of use:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-term.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-term.html)

---

<div class="post-metadata">

**Author:** ![basharz](https://avatars.discourse-cdn.com/v4/letter/b/e99b99/32.png) [@basharz](https://discuss.elastic.co/u/basharz)\
**Post date:** [May 4, 2017, 5:33am UTC](https://discuss.elastic.co/t/tolerance-spelling/83028/3 "2017-05-04T05:33:58Z")

</div>

Hi, you can use the phonetic-matching [https://www.elastic.co/guide/en/elasticsearch/guide/current/phonetic-matching.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/phonetic-matching.html)

---

<div class="post-metadata">

**Author:** ![geekpete](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/geekpete/32/20409_2.png) [@geekpete](https://discuss.elastic.co/u/geekpete)\
**Post date:** [May 4, 2017, 5:46am UTC](https://discuss.elastic.co/t/tolerance-spelling/83028/4 "2017-05-04T05:46:45Z")

</div>

Another great tip!

---

<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:** [June 1, 2017, 5:47am UTC](https://discuss.elastic.co/t/tolerance-spelling/83028/5 "2017-06-01T05:47:21Z")

</div>

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