# Something like Wildcard Filter?

**URL:** <https://discuss.elastic.co/t/something-like-wildcard-filter/4015>\
**Category:** Elasticsearch\
**Created:** [March 2, 2011, 3:06pm UTC](https://discuss.elastic.co/t/something-like-wildcard-filter/4015 "2011-03-02T15:06:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![timscott](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timscott/32/3220_2.png) [@timscott](https://discuss.elastic.co/u/timscott)\
**Post date:** [March 2, 2011, 3:06pm UTC](https://discuss.elastic.co/t/something-like-wildcard-filter/4015/1 "2011-03-02T15:06:53Z")

</div>

Is there any way to filter a non-analyzed by "starts with?" Prefix  
filter does work because it looks at each term whereas I need to look  
at the whole value of the field. What I need is like the wildcard  
query, except a filter. Is there any way to accomplish this? I spent  
some time with the script filter but came up empty so far.

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 2, 2011, 3:10pm UTC](https://discuss.elastic.co/t/something-like-wildcard-filter/4015/2 "2011-03-02T15:10:24Z")

</div>

On Wed, 2011-03-02 at 07:06 -0800, Tim Scott wrote:

> Is there any way to filter a non-analyzed by "starts with?" Prefix  
> filter does work because it looks at each term whereas I need to look  
> at the whole value of the field. What I need is like the wildcard  
> query, except a filter. Is there any way to accomplish this? I spent  
> some time with the script filter but came up empty so far.

If I've understood you correctly, then the prefix filter should work.

Do you want to gist ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)) an example  
showing what you're trying to achieve and why it doesn't work?

clint

---

<div class="post-metadata">

**Author:** ![timscott](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timscott/32/3220_2.png) [@timscott](https://discuss.elastic.co/u/timscott)\
**Post date:** [March 2, 2011, 3:35pm UTC](https://discuss.elastic.co/t/something-like-wildcard-filter/4015/3 "2011-03-02T15:35:31Z")

</div>

Prefix filter does not work. I can gist if needed, but it's pretty  
simple to explain. Assume three documents with values in a certain  
field of:

"blue"  
"blue red"  
"red blue"

I need to filter documents where the field starts with "blue" (first  
and second documents). A preview filter of "blue" will match all  
three. That's because (it seems) it looks at terms (individual  
words).

On Mar 2, 9:10 am, Clinton Gormley [clin...@iannounce.co.uk](mailto:clin...@iannounce.co.uk) wrote:

> On Wed, 2011-03-02 at 07:06 -0800, Tim Scott wrote:
> 
> > Is there any way to filter a non-analyzed by "starts with?" Prefix  
> > filter does work because it looks at each term whereas I need to look  
> > at the whole value of the field. What I need is like the wildcard  
> > query, except a filter. Is there any way to accomplish this? I spent  
> > some time with the script filter but came up empty so far.
> 
> If I've understood you correctly, then the prefix filter should work.
> 
> Do you want to gist ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)) an example  
> showing what you're trying to achieve and why it doesn't work?
> 
> clint

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 2, 2011, 4:01pm UTC](https://discuss.elastic.co/t/something-like-wildcard-filter/4015/4 "2011-03-02T16:01:39Z")

</div>

On Wed, 2011-03-02 at 07:35 -0800, Tim Scott wrote:

> Prefix filter does not work. I can gist if needed, but it's pretty  
> simple to explain. Assume three documents with values in a certain  
> field of:
> 
> "blue"  
> "blue red"  
> "red blue"
> 
> I need to filter documents where the field starts with "blue" (first  
> and second documents). A preview filter of "blue" will match all  
> three. That's because (it seems) it looks at terms (individual  
> words).

You said you wanted to use this on a non-analyzed field.

in which case, a prefix query works:

> <https://gist.github.com/clintongormley/851150>

clint

---

<div class="post-metadata">

**Author:** ![timscott](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timscott/32/3220_2.png) [@timscott](https://discuss.elastic.co/u/timscott)\
**Post date:** [March 2, 2011, 11:51pm UTC](https://discuss.elastic.co/t/something-like-wildcard-filter/4015/5 "2011-03-02T23:51:31Z")

</div>

I'm feeling stupid again. The field is question _was_ mapped not-  
analyzed. However somehow the mapping got changed. I fixed that, and  
it works just as you said. Thanks for taking the time to prove it.

On Mar 2, 10:01 am, Clinton Gormley [clin...@iannounce.co.uk](mailto:clin...@iannounce.co.uk) wrote:

> On Wed, 2011-03-02 at 07:35 -0800, Tim Scott wrote:
> 
> > Prefix filter does not work. I can gist if needed, but it's pretty  
> > simple to explain. Assume three documents with values in a certain  
> > field of:
> 
> > "blue"  
> > "blue red"  
> > "red blue"
> 
> > I need to filter documents where the field starts with "blue" (first  
> > and second documents). A preview filter of "blue" will match all  
> > three. That's because (it seems) it looks at terms (individual  
> > words).
> 
> You said you wanted to use this on a non-analyzed field.
> 
> in which case, a prefix query works:
> 
> [ElasticSearch prefix query · GitHub](https://gist.github.com/851150)
> 
> clint

---

<div class="post-metadata">

**Author:** ![zouxcs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zouxcs/32/920_2.png) [@zouxcs](https://discuss.elastic.co/u/zouxcs)\
**Post date:** [July 31, 2014, 2:24am UTC](https://discuss.elastic.co/t/something-like-wildcard-filter/4015/6 "2014-07-31T02:24:44Z")

</div>

I have the same question now,how did you solve it?give me a hint.Thank you

---

<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 6, 2017, 1:12am UTC](https://discuss.elastic.co/t/something-like-wildcard-filter/4015/7 "2017-07-06T01:12:04Z")

</div>


