# Generating shingles with synonyms in Elasticsearch

**URL:** <https://discuss.elastic.co/t/generating-shingles-with-synonyms-in-elasticsearch/294964>\
**Category:** Elasticsearch\
**Created:** [January 20, 2022, 2:58pm UTC](https://discuss.elastic.co/t/generating-shingles-with-synonyms-in-elasticsearch/294964 "2022-01-20T14:58:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yawan\_Gupta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yawan_gupta/32/100632_2.png) [@Yawan\_Gupta](https://discuss.elastic.co/u/Yawan_Gupta)\
**Post date:** [January 20, 2022, 2:58pm UTC](https://discuss.elastic.co/t/generating-shingles-with-synonyms-in-elasticsearch/294964/1 "2022-01-20T14:58:09Z")

</div>

I have a file of alternate spellings for the terms in my index. I want to produce bigrams containing those alternate spellings for particular terms. For example, I have `biriyani, biryani, briyani` in my alternate spellings csv file and my field contains the text `Chicken Biryani` . I want to be able to produce `chicken biryani, chicken biriyani, chicken briyani` tokens.

Now, if I use a whitespace tokenizer with a synonym filter, the following tokens are generated `chicken, biriyani, biryani, briyani` which is expected. Now if I apply a shingle filter then, the tokens generated are `chicken, chicken biryani, biryani, biryani biriyani, biriyani, biriyani briyani, briyani` . This token stream contains shingles of synonyms of the word itself which should not be there and it does not contain tokens with `chicken [alternate spellings of biryani]` like chicken biriyani or chicken briyani, etc. If I place shingle filter before the synonym filter, then it only adds synonym tokens for the unigram: `chicken, chicken biryani, biriyani, biryani, briyani` . Is there a way to generate tokens that contain synonyms at the same position as the original token, or in this case `chicken biryani, chicken biriyani, chicken briyani`

I am running Elasticsearch 5.6. Sample settings for testing:

```auto
PUT test_bigram
{
  "settings": {
    "index": {
      "analysis": {
        "filter": {
          "synonym": {
            "type": "synonym",
            "synonyms": [
              "biriyani, biryani, briyani"
            ]
          }
        },
        "analyzer": {
          "synonym_analyzer": {
            "filter": [
              "synonym"
            ],
            "type": "custom",
            "tokenizer": "whitespace"
          },
          "shingle_synonym": {
            "type": "custom",
            "tokenizer": "whitespace",
            "filter": [
              "shingle",
              "synonym"
            ]
          },
          "synonym_shingle": {
            "type": "custom",
            "tokenizer": "whitespace",
            "filter": [
              "synonym",
              "shingle"
            ]
          }
        }
      }
    }
  }
}

```

---

<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:** [February 17, 2022, 2:58pm UTC](https://discuss.elastic.co/t/generating-shingles-with-synonyms-in-elasticsearch/294964/2 "2022-02-17T14:58:16Z")

</div>

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