# Token filter doesn't work on wildcard-search

**URL:** <https://discuss.elastic.co/t/token-filter-doesnt-work-on-wildcard-search/264588>\
**Category:** Elasticsearch\
**Created:** [February 17, 2021, 2:31pm UTC](https://discuss.elastic.co/t/token-filter-doesnt-work-on-wildcard-search/264588 "2021-02-17T14:31:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TallGuru](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@TallGuru](https://discuss.elastic.co/u/TallGuru)\
**Post date:** [February 17, 2021, 2:31pm UTC](https://discuss.elastic.co/t/token-filter-doesnt-work-on-wildcard-search/264588/1 "2021-02-17T14:31:07Z")

</div>

Hi

I'm trying to implement a filter to find compounded words and needs to combine it with wildcard-search but it doesn't work.

**Example case:**  
There are documents with names "Coca-Cola", "Cocacola" and "Coca Cola". I want hits from all of them when searching on each word.

**My mappings:**

- "whitespace" to create token for each word
- "shingle" to compound words
- "pattern\_replace" to remove spaces etc

```auto
PUT /testindex
{
  "mappings": {
    "properties": {
      "name": {
        "type": "text",
        "analyzer": "test_analyzer"
      }
    }
  },
  "settings": {
    "analysis": {
      "analyzer": {
        "test_analyzer": {
          "type": "custom",
          "tokenizer": "whitespace",
          "filter": [
            "lowercase",
            "shingle",
            "remove_special_characters_filter"
          ]
        }
      },
      "remove_special_characters_filter": {
        "type": "pattern_replace",
        "pattern": """[^\p{L}\p{Nd}]""",
        "replacement": ""
      }
    }
  }
}

```

**Creating documents:**

```auto
PUT /testindex/_doc/1
{
  "name": "Coca-Cola"
}
PUT /testindex/_doc/2
{
  "name": "CocaCola"
}
PUT /testindex/_doc/3
{
  "name": "Coca Cola"
}

```

**Searching**  
_match hits all documents:_

```auto
GET /testindex/_search
{
  "query": {
    "match": {
      "name": "Coca-Cola"
    }
  }
}

```

_wildcard hits no documents (nor without the wildcards):_

```auto
GET /testindex/_search
{
  "query": {
    "wildcard": {
      "name": {
        "value": "*Coca-Cola*"
      }
    }
  }
}

```

_removing the hyphen hits all documents:_

```auto
GET /testindex/_search
{
  "query": {
    "wildcard": {
      "name": {
        "value": "*CocaCola*"
      }
    }
  }
}

```

Any suggestions?

---

<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:** [March 17, 2021, 2:31pm UTC](https://discuss.elastic.co/t/token-filter-doesnt-work-on-wildcard-search/264588/2 "2021-03-17T14:31:33Z")

</div>

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