# Elastic Search text similarity search

**URL:** https://discuss.elastic.co/t/elastic-search-text-similarity-search/305643
**Category:** Elasticsearch
**Created:** [May 25, 2022, 10:20pm UTC](https://discuss.elastic.co/t/elastic-search-text-similarity-search/305643 "2022-05-25T22:20:33Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![gkumargaur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gkumargaur/32/106165_2.png) [@gkumargaur](https://discuss.elastic.co/u/gkumargaur)
#### Post date: [May 25, 2022, 10:20pm UTC](https://discuss.elastic.co/t/elastic-search-text-similarity-search/305643/1 "2022-05-25T22:20:33Z")

</div>

what is the best way to search San Jose and SanJose in Elasticsearch. Data is stored as text and correct value in ES is San Jose.  
Sample query not working:

```auto
{
        "match" : {
          "cssot_city" : {
            "query" : "SanJose",
            "operator" : "OR",
            "fuzziness" : "AUTO",
            "prefix_length" : 0,
            "max_expansions" : 50,
            "fuzzy_transpositions" : true,
            "lenient" : true,
            "zero_terms_query": "all",
            "auto_generate_synonyms_phrase_query" : true,
            "boost" : 1.0
          }
        }
      }

```

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [May 25, 2022, 10:59pm UTC](https://discuss.elastic.co/t/elastic-search-text-similarity-search/305643/2 "2022-05-25T22:59:24Z")

</div>

Hi @gkumargaur !

I found two options:

1 - In this [post](https://discuss.elastic.co/t/apply-fuzzy-search-and-searching-with-without-spaces/242964/3) the user created an analyzer to index the words without the white space.

2 - You can use a suggester to suggest the closest term to the user, it would be a "did you mean".

Ex:

```auto
PUT idx_did_you_mean
{
  "settings": {
    "analysis": {
      "filter": {
        "shingle_filter": {
          "max_shingle_size": "3",
          "min_shingle_size": "2",
          "type": "shingle"
        }
      },
      "analyzer": {
        "shingle_analyzer": {
          "filter": [
            "lowercase",
            "shingle_filter"
          ],
          "type": "custom",
          "tokenizer": "standard"
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "fields": {
          "suggest": {
            "type": "text",
            "analyzer": "shingle_analyzer"
          }
        }
      }
    }
  }
}

POST idx_did_you_mean/_doc
{
  "title":"San Jose"
}

GET idx_did_you_mean/_search
{
  "suggest": {
    "text": "sanjose city",
    "did_you_mean": {
      "phrase": {
        "field": "title.suggest",
        "size": 5
      }
    }
  }
}

```

---

<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 22, 2022, 11:00pm UTC](https://discuss.elastic.co/t/elastic-search-text-similarity-search/305643/3 "2022-06-22T23:00:12Z")

</div>

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