# Unexpected match when using edgeNgram filter

**URL:** <https://discuss.elastic.co/t/unexpected-match-when-using-edgengram-filter/268105>\
**Category:** Elasticsearch\
**Created:** [March 23, 2021, 2:15pm UTC](https://discuss.elastic.co/t/unexpected-match-when-using-edgengram-filter/268105 "2021-03-23T14:15:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt4](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@matt4](https://discuss.elastic.co/u/matt4)\
**Post date:** [March 23, 2021, 2:15pm UTC](https://discuss.elastic.co/t/unexpected-match-when-using-edgengram-filter/268105/1 "2021-03-23T14:15:27Z")

</div>

I encountered some unexpected matches when I set up a field with an analyzer that contains an edgeNgram filter.

This is how I set up the mappings and the settings:

```
PUT test-index
{
  "mappings": {
    "properties": {
      "name" : { "type" : "text", "analyzer" : "my_custom_analyzer" }
    }
  },
  "settings": {
    "analysis": {
      "analyzer": {
        "my_custom_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "char_filter": [
            "html_strip"
          ],
          "filter": [
            "my_edge_gram"
          ]
        }
      },
      "filter": {
        "my_edge_gram": {
          "type": "edge_ngram",
          "min_gram": 1,
          "max_gram": 20
        }
      }
    }
  }
}

```

And then I added three documents like this:

```
PUT test-index/_doc/1
{
    "name": "Mario"
}

PUT test-index/_doc/2
{
    "name": "Maria"
}

PUT test-index/_doc/3
{
    "name": "Merle"
}

```

Then when I executed this query:

```
GET test-index/_search
{
    "query": {
        "match" : {
            "name" : "Mario"
        }
    }
}

```

I got all three documents.

I was under the impression that edgeNgram meant that a text field like "Mario" is split into "M", "Ma", "Mar", "Mari" and "Mario". So I thought when I look for "M" I would get all the documents, when I look for "Ma", "Mar" or "Mari", I would get the documents "Mario" and "Maria" and when I look for "Mario", I would only get the document "Mario".

It seems like there is something that I did not understand about edgeNgram. Can you explain it to me?

---

<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:** [April 20, 2021, 2:16pm UTC](https://discuss.elastic.co/t/unexpected-match-when-using-edgengram-filter/268105/2 "2021-04-20T14:16:18Z")

</div>

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