# Resolving synonyms and document frequency for autocomplete querying in elasticsearch

**URL:** <https://discuss.elastic.co/t/resolving-synonyms-and-document-frequency-for-autocomplete-querying-in-elasticsearch/182868>\
**Category:** Elasticsearch\
**Created:** [May 27, 2019, 9:08am UTC](https://discuss.elastic.co/t/resolving-synonyms-and-document-frequency-for-autocomplete-querying-in-elasticsearch/182868 "2019-05-27T09:08:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![User\_User](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/user_user/32/43769_2.png) [@User\_User](https://discuss.elastic.co/u/User_User)\
**Post date:** [May 27, 2019, 9:08am UTC](https://discuss.elastic.co/t/resolving-synonyms-and-document-frequency-for-autocomplete-querying-in-elasticsearch/182868/1 "2019-05-27T09:08:06Z")

</div>

I am trying to build an ElasticSearch index which will have documents with product names, for instance of laptops -

```auto
{ "name" : "Laptop Blue I7"}

```

Then I want to use it for autocomplete suggestion by querying the ES index. I have 2 main constraints:

1. There can be Synonyms of the name -

I want to define Synonyms for terms, like "Notebook" for "Laptop" The ingested documents can be of the following kind -

```auto
"Laptop Blue I7"
"Laptop Blue I7"
"Laptop Blue I7"
"Laptop Blue I7"
"Laptop Red I7"
"Laptop Red I7"
"Notebook Blue I7"

```

Now, I am adding the following settings and mapping file while creating the index -

```auto
{
  "settings": {
    "index": {
      "analysis": {
        "filter" : {
                    "synonym" : {
                        "type" : "synonym",
                        "synonyms" : ["Laptop,Notebook"]
                    }
                },
        "analyzer": {
        "synonym" : {
                        "tokenizer" : "keyword",
                        "filter" : ["synonym"]
                    }
}}}}, 
"mappings": {
    "catalog": {
      "properties": {
        "name": {
          "type": "text",
          "analyzer": "synonym"
        }
      }
    }
  }
}

```

1. Querying -

When I query the data, with "Notebook", the preferred response should be ordered in terms of frequency and synonym. However, when I query, the response is normally independent of the synonym and frequency. I use the following query -

```auto
/_search
{"query": {
        "query_string" : {"default_field" : "name", "query" : "Notebook"}
            } }

```

The response I get is -

```auto
"Notebook Blue I7"

```

While I would hope the response to be either of the following -

```auto
"Laptop Blue I7"
"Laptop Red I7"

```

or

```auto
"Notebook Blue I7"
"Laptop Blue I7"
"Laptop Red I7"

```

Any insights in resolving this would be helpful. Thanks

---

<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 24, 2019, 9:08am UTC](https://discuss.elastic.co/t/resolving-synonyms-and-document-frequency-for-autocomplete-querying-in-elasticsearch/182868/2 "2019-06-24T09:08:12Z")

</div>

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