# Highlighting with edge ngram token + synonym filter

**URL:** <https://discuss.elastic.co/t/highlighting-with-edge-ngram-token-synonym-filter/239600>\
**Category:** Elasticsearch\
**Created:** [July 2, 2020, 9:36am UTC](https://discuss.elastic.co/t/highlighting-with-edge-ngram-token-synonym-filter/239600 "2020-07-02T09:36:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![b\_b\_inc](https://avatars.discourse-cdn.com/v4/letter/b/a698b9/32.png) [@b\_b\_inc](https://discuss.elastic.co/u/b_b_inc)\
**Post date:** [July 2, 2020, 9:36am UTC](https://discuss.elastic.co/t/highlighting-with-edge-ngram-token-synonym-filter/239600/1 "2020-07-02T09:36:16Z")

</div>

Hi,  
For my use case I need to use both an edge-ngram _token filter_ and a synonym filter, and then highlight the appropriate token in the result using highlight.  
Considering I've to use both edge-ngram and synonym, I've to use edge-ngram _token filter_ as against the edge ngram _tokenizer_; and apply them in the order of synonym filter -\> edge ngram _token filter_.

However this creates a issue in the highlighting (which as per me, comes because of no position increments).

Please look at the below image to see the highlight created when I search for "index". Even "industrial" (as a whole gets highlighted)

```auto
    PUT test1/
    {
      "settings": {
        "analysis": {
          "filter": {
            "my_edge_ngram_filter": {
              "token_chars": [
                "letter",
                "digit"
              ],
              "min_gram": "1",
              "type": "edgeNGram",
              "max_gram": "12"
            },
            "synonym_normal": {
              "type": "synonym",
              "synonyms": [
                "index, bond",
                "industrial, industry"
              ]
            }
          },
          "tokenizer": {
            "my_edge_ngram_tokenizer": {
              "token_chars": [
                "letter",
                "digit"
              ],
              "min_gram": "1",
              "type": "edgeNGram",
              "max_gram": "12"
            }
          },
          "analyzer": {
            "synonym_edgengram": {
              "filter": [
                "synonym_normal",
                "my_edge_ngram_filter"
              ],
              "tokenizer": "whitespace",
              "type" : "custom"
            },
            "edgengram_tokenizer": {
              "tokenizer": "my_edge_ngram_tokenizer",
              "type" : "custom"
            }
          }
        }
      },
      "mappings": {
        "test1": {
          "properties": {
            "name": {
              "type": "text",
              "fields": {
                "field_synonym_edgengram": {
                  "type": "text",
                  "analyzer": "synonym_edgengram",
                  "fielddata": true
                },
                "field_edgengram_tokenizer": {
                  "type": "text",
                  "analyzer": "edgengram_tokenizer",
                  "fielddata": true
                }
              }
            }
          }
        }
      }
    }

```

Indexing one document:

```auto
POST test1/test1/
{
 "name" :"index industrial"
}

```

Query1 with highlight:

```auto
    GET test1/_search
    {
      "query": {
        "match": {
          "name.field_synonym_edgengram": "index "
        }
      },
      "highlight": {
        "fields": {
          "name.field_synonym_edgengram": {}
        }
      }
    }

```

Result:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/9/293a5f1849d35df6ba42a97212c211c98183ec45.png)

Where as you can see; even "industrial" as a whole instead of just "ind" gets highlighted

Now, if I run the same query using edge-ngram _tokenizer_ (and without syonyms):

Query2:

```auto
    GET test1/_search
    {
      "query": {
        "match": {
          "name.field_edgengram_tokenizer": "index "
        }
      },
      "highlight": {
        "fields": {
          "name.field_edgengram_tokenizer": {}
        }
      }
    }

```

It gets properly highlighted:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/5/e59629700df594a4c270070893bcea4eda4a0f44.png)

I believe this is due to the position increments seen in edge-ngram _tokenizer_ as against _filter_. Any way to get around this highlighting issue?

---

<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:** [July 30, 2020, 9:36am UTC](https://discuss.elastic.co/t/highlighting-with-edge-ngram-token-synonym-filter/239600/2 "2020-07-30T09:36:19Z")

</div>

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