# "Did you mean" feature using elasticsearch

**URL:** <https://discuss.elastic.co/t/did-you-mean-feature-using-elasticsearch/150886>\
**Category:** Elasticsearch\
**Created:** [October 3, 2018, 12:19pm UTC](https://discuss.elastic.co/t/did-you-mean-feature-using-elasticsearch/150886 "2018-10-03T12:19:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikesh/32/86579_2.png) [@Nikesh](https://discuss.elastic.co/u/Nikesh)\
**Post date:** [October 3, 2018, 12:19pm UTC](https://discuss.elastic.co/t/did-you-mean-feature-using-elasticsearch/150886/1 "2018-10-03T12:19:50Z")

</div>

Hi all,  
I am implementing "did you mean" technology using Elasticsearch. After doing some research I found out, phrase suggesters is designed only for this purpose. But I am facing some issues with it.  
My mapping document:

```
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "analysis": {
        "analyzer": {
          "trigram": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": ["standard", "shingle"]
          },
          "reverse": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": ["standard", "reverse"]
          }
        },
        "filter": {
          "shingle": {
            "type": "shingle",
            "min_shingle_size": 2,
            "max_shingle_size": 3
          }
        }
      }
    }
  },
  "mappings": {
    "test": {
      "properties": {
        "title": {
          "type": "text",
          "fields": {
            "trigram": {
              "type": "text",
              "analyzer": "trigram"
            },
            "reverse": {
              "type": "text",
              "analyzer": "reverse"
            }
          }
        }
      }
    }
  }
}

```

My document is :

```
{"title": "nobel prize"}

```

My search query is:

```
{
  "suggest": {
    "text": "noble prze",
    "simple_phrase": {
      "phrase": {
        "field": "title.trigram",
        "size": 1,
        "gram_size": 3,
        "direct_generator": [ {
          "field": "title.trigram",
          "suggest_mode": "always"
        } ],
        "highlight": {
          "pre_tag": "<em>",
          "post_tag": "</em>"
        }
      }
    }
  }
}

```

The query works fine if there is mismatch with only one character in the text to be searched. Otherwise the phrase suggested corrects only one character.  
The output is:

```
{
    "took": 6,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 0,
        "max_score": 0,
        "hits": []
    },
    "suggest": {
        "simple_phrase": [
            {
                "text": "noble prze",
                "offset": 0,
                "length": 10,
                "options": [
                    {
                        "text": "nobel prze",
                        "highlighted": "<em>nobel</em> prze",
                        "score": 0.16992487
                    }
                ]
            }
        ]
    }
}
```

---

<div class="post-metadata">

**Author:** ![Nikesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikesh/32/86579_2.png) [@Nikesh](https://discuss.elastic.co/u/Nikesh)\
**Post date:** [October 4, 2018, 1:01pm UTC](https://discuss.elastic.co/t/did-you-mean-feature-using-elasticsearch/150886/2 "2018-10-04T13:01:51Z")

</div>

@elastic

---

<div class="post-metadata">

**Author:** ![Nikesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikesh/32/86579_2.png) [@Nikesh](https://discuss.elastic.co/u/Nikesh)\
**Post date:** [October 15, 2018, 10:42am UTC](https://discuss.elastic.co/t/did-you-mean-feature-using-elasticsearch/150886/4 "2018-10-15T10:42:35Z")

</div>

@rjernst

---

<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:** [November 12, 2018, 10:42am UTC](https://discuss.elastic.co/t/did-you-mean-feature-using-elasticsearch/150886/5 "2018-11-12T10:42:38Z")

</div>

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