# Char\_filter and lowercase not working for search\_analyzer

**URL:** <https://discuss.elastic.co/t/char-filter-and-lowercase-not-working-for-search-analyzer/195074>\
**Category:** Elasticsearch\
**Created:** [August 13, 2019, 6:09pm UTC](https://discuss.elastic.co/t/char-filter-and-lowercase-not-working-for-search-analyzer/195074 "2019-08-13T18:09:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KrisMeister](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krismeister/32/23248_2.png) [@KrisMeister](https://discuss.elastic.co/u/KrisMeister)\
**Post date:** [August 13, 2019, 6:09pm UTC](https://discuss.elastic.co/t/char-filter-and-lowercase-not-working-for-search-analyzer/195074/1 "2019-08-13T18:09:58Z")

</div>

I've been experimenting with many different iterations of the below but haven't been able to match all the cases I'd like to.

My objective is to match the following cases:

- "7-eleven" or "7eleven" to the text "7-Eleven"
- "At&t" or "ATT" to "AT&T"

## Mapping:

```auto
{
  "settings": {
    "analysis": {
      "char_filter" : {
        "remove_special_chars" : {
          "type" : "mapping",
          "mappings" : [
            "-=>",
            "&=>"
          ]
        }
      },
      "tokenizer": {
        "autocomplete": {
          "type": "edge_ngram",
          "min_gram": 1,
          "max_gram": 15,
          "token_chars": [
            "letter",
            "digit"
          ]
        }
      },
      "analyzer": {
        "autocomplete": {
          "tokenizer": "autocomplete",
          "filter": [
            "lowercase"
          ],
          "char_filter" : ["remove_special_chars"]
        },
        "autocomplete_search": {
          "tokenizer": "standard",
          "filter": [
            "lowercase"
          ],
          "char_filter" : ["remove_special_chars"]
        }
      }
    }
  },
  "mappings": {
    "vendors": {
      "_all": {},
      "properties": {
        "searchable": {
          "type": "text",
          "analyzer": "autocomplete",
          "search_analyzer": "autocomplete_search"
        }
      }
    }
  }
}

```

## Add Document:

```auto
put my_test_index/vendors/1
{
    "searchable": "7-Eleven"
}

```

## Querying the documents

```auto
{
  "sort" : [
    "_score"
  ],
  "query": {
    "bool": {
      "should": [
          { "match" :
            { "searchable" :
              {
                "query" : "7-eleven",
                "operator" : "and"
              }
            }
          }
        ]
    }
  }
}

```

The above works for a query of `7eleven` but not `7-eleven`. Is something wrong with my syntax?Why is the query not going through the search analyzer?

---

<div class="post-metadata">

**Author:** ![KrisMeister](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krismeister/32/23248_2.png) [@KrisMeister](https://discuss.elastic.co/u/KrisMeister)\
**Post date:** [August 13, 2019, 7:14pm UTC](https://discuss.elastic.co/t/char-filter-and-lowercase-not-working-for-search-analyzer/195074/2 "2019-08-13T19:14:15Z")

</div>

OMG, there was some code deep within our project which was escaping the hyphen character.  
The code above works as expected.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 14, 2019, 7:49am UTC](https://discuss.elastic.co/t/char-filter-and-lowercase-not-working-for-search-analyzer/195074/3 "2019-08-14T07:49:36Z")

</div>

glad you found it, for future reference you might want to take a look at the [explain API](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/search-explain.html) as well as the [explain parameter](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/search-request-body.html#request-body-search-explain) in the search bodry.

---

<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:** [September 11, 2019, 7:49am UTC](https://discuss.elastic.co/t/char-filter-and-lowercase-not-working-for-search-analyzer/195074/4 "2019-09-11T07:49:47Z")

</div>

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