# Match against stored wildcard string

**URL:** <https://discuss.elastic.co/t/match-against-stored-wildcard-string/34725>\
**Category:** Elasticsearch\
**Created:** [November 16, 2015, 7:52pm UTC](https://discuss.elastic.co/t/match-against-stored-wildcard-string/34725 "2015-11-16T19:52:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![horte](https://avatars.discourse-cdn.com/v4/letter/h/9fc348/32.png) [@horte](https://discuss.elastic.co/u/horte)\
**Post date:** [November 16, 2015, 7:52pm UTC](https://discuss.elastic.co/t/match-against-stored-wildcard-string/34725/1 "2015-11-16T19:52:47Z")

</div>

I want to be able to match a given string against a field that contains a value where an asterix is a placeholder for any given value.

I have a string `subdomain.domain-c.com` and I want to return all documents that does not contain the exact match for `subdomain.domain-c.com` or the record `*.domain-c.com`. In the below example it should return Document 2. Is this possible?

**Document 1**

```auto
{
domains: [www.domain-a.com, domain-b.com, *.domain-c.com] 
}

```

**Document 2**

```auto
{
domains: [www.domain-a.com, domain-b.com] 
}

```

**Document 3**

```auto
{
domains: [subdomain.domain-c.com] 
}

```

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [November 18, 2015, 4:44pm UTC](https://discuss.elastic.co/t/match-against-stored-wildcard-string/34725/2 "2015-11-18T16:44:38Z")

</div>

Hi Fredrik,

unfortunately I think it is not possible to use wildcards in field values and then match them against a concrete query, but I have some hints that might be useful towards a solution.

This [blog post](http://andrewwhitby.com/2014/11/23/domain-name-analyzer-with-elasticsearch/) that explains how to use the [path hierarchy tokenizer](https://www.elastic.co/guide/en/elasticsearch/reference/2.0/analysis-pathhierarchy-tokenizer.html) for domain names, so the parts of your domains will be stored in reverse order in the index. With this you might be able to use a `match` or `prefix` query in a `must_not` clause of a `bool` query to archieve what you are looking for.

I dont know about the exact use case you have, but maybe you can drop the wildcard in the subdomains and then do a negated search on the "[domain-c.com](http://domain-c.com)" part using the reversed domain name? Not sure this completely solves your problem but maybe it helps.

---

<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 5, 2017, 11:37pm UTC](https://discuss.elastic.co/t/match-against-stored-wildcard-string/34725/3 "2017-07-05T23:37:32Z")

</div>


