title: Generating shingles with synonyms in Elasticsearch
body: <p>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 <code>biriyani, biryani, briyani</code> in my alternate spellings csv file and my field contains the text <code>Chicken Biryani</code>. I want to be able to produce <code>chicken biryani, chicken biriyani, chicken briyani</code> tokens.</p>
  <p>Now, if I use a whitespace tokenizer with a synonym filter, the following tokens are generated <code>chicken, biriyani, biryani, briyani</code> which is expected. Now if I apply a shingle filter then, the tokens generated are <code>chicken, chicken biryani, biryani, biryani biriyani, biriyani, biriyani briyani, briyani</code>. This token stream contains shingles of synonyms of the word itself which should not be there and it does not contain tokens with <code>chicken [alternate spellings of biryani]</code> 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: <code>chicken, chicken biryani, biriyani, biryani, briyani</code>. Is there a way to generate tokens that contain synonyms at the same position as the original token, or in this case <code>chicken biryani, chicken biriyani, chicken briyani</code></p>
  <p>Sample settings for testing:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>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"
              ]
            }
          }
        }
      }
    }
  }</code></pre>
  </div>
  </div>
  </p>
  <p>I am running Elasticsearch 5.6</p>