# Using filtered query with a wildcard

**URL:** <https://discuss.elastic.co/t/using-filtered-query-with-a-wildcard/22107>\
**Category:** Elasticsearch\
**Created:** [February 11, 2015, 8:03pm UTC](https://discuss.elastic.co/t/using-filtered-query-with-a-wildcard/22107 "2015-02-11T20:03:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sagar\_Shah](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@Sagar\_Shah](https://discuss.elastic.co/u/Sagar_Shah)\
**Post date:** [February 11, 2015, 8:03pm UTC](https://discuss.elastic.co/t/using-filtered-query-with-a-wildcard/22107/1 "2015-02-11T20:03:10Z")

</div>

Hello everyone,  
I came across few articles that says filtered query are generally faster.  
I need to perform some wildcard search on one of the fields.  
So my questions is...  
Can I perform wildcard search on the field along with filtered query? If  
so, can anyone please provide an example?

I tried few combinations of JSON for request body, but that did not work.  
Example:

Method:POST

{  
"query": {  
"filtered": {  
"filter": {  
"bool": {  
"must": [  
{  
"wildcard": {  
"wildcardField": "_Text_"  
}  
},  
{  
"term": {  
"messageId": "14406"  
}  
}  
]  
}  
}  
}  
}  
}

Appreciate your inputs!

Regards,  
Sagar Shah

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/67eb86d0-1f10-47a0-94e0-b5f6ed166d4d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/67eb86d0-1f10-47a0-94e0-b5f6ed166d4d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 11, 2015, 8:56pm UTC](https://discuss.elastic.co/t/using-filtered-query-with-a-wildcard/22107/2 "2015-02-11T20:56:27Z")

</div>

Not answering to your question, but...

If you are about performance, don’t use wildcard queries.  
But prefer ngram analyzers with match queries.

That will be really more efficient.

In particular here, wildcard beginning with a star is the worse scenario performance wise.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)

> Le 11 févr. 2015 à 21:03, Sagar Shah [sagarshah1983@gmail.com](mailto:sagarshah1983@gmail.com) a écrit :
> 
> Hello everyone,  
> I came across few articles that says filtered query are generally faster.  
> I need to perform some wildcard search on one of the fields.  
> So my questions is...  
> Can I perform wildcard search on the field along with filtered query? If so, can anyone please provide an example?
> 
> I tried few combinations of JSON for request body, but that did not work.  
> Example:
> 
> Method:POST
> 
> {  
> "query": {  
> "filtered": {  
> "filter": {  
> "bool": {  
> "must": [  
> {  
> "wildcard": {  
> "wildcardField": "_Text_"  
> }  
> },  
> {  
> "term": {  
> "messageId": "14406"  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }
> 
> Appreciate your inputs!
> 
> Regards,  
> Sagar Shah
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com) [mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/67eb86d0-1f10-47a0-94e0-b5f6ed166d4d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/67eb86d0-1f10-47a0-94e0-b5f6ed166d4d%40googlegroups.com) [https://groups.google.com/d/msgid/elasticsearch/67eb86d0-1f10-47a0-94e0-b5f6ed166d4d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/67eb86d0-1f10-47a0-94e0-b5f6ed166d4d%40googlegroups.com?utm_medium=email&utm_source=footer).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/B8FA2C00-FBA6-4550-B839-9D31FF47752D%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/B8FA2C00-FBA6-4550-B839-9D31FF47752D%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Sagar\_Shah](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@Sagar\_Shah](https://discuss.elastic.co/u/Sagar_Shah)\
**Post date:** [February 12, 2015, 6:37am UTC](https://discuss.elastic.co/t/using-filtered-query-with-a-wildcard/22107/3 "2015-02-12T06:37:06Z")

</div>

Thank you David.  
I will evaluate and look into ngram analyzer to see how it can help on the  
specific scenario.  
Appreciate your help!

On Thu, Feb 12, 2015 at 2:26 AM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Not answering to your question, but...
> 
> If you are about performance, don’t use wildcard queries.  
> But prefer ngram analyzers with match queries.
> 
> That will be really more efficient.
> 
> In particular here, wildcard beginning with a star is the worse scenario  
> performance wise.
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)  
> [http://Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs  
> [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 11 févr. 2015 à 21:03, Sagar Shah [sagarshah1983@gmail.com](mailto:sagarshah1983@gmail.com) a écrit :
> 
> Hello everyone,  
> I came across few articles that says filtered query are generally faster.  
> I need to perform some wildcard search on one of the fields.  
> So my questions is...  
> Can I perform wildcard search on the field along with filtered query? If  
> so, can anyone please provide an example?
> 
> I tried few combinations of JSON for request body, but that did not work.  
> Example:
> 
> Method:POST
> 
> {  
> "query": {  
> "filtered": {  
> "filter": {  
> "bool": {  
> "must": [  
> {  
> "wildcard": {  
> "wildcardField": "_Text_"  
> }  
> },  
> {  
> "term": {  
> "messageId": "14406"  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }
> 
> Appreciate your inputs!
> 
> Regards,  
> Sagar Shah
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/67eb86d0-1f10-47a0-94e0-b5f6ed166d4d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/67eb86d0-1f10-47a0-94e0-b5f6ed166d4d%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/67eb86d0-1f10-47a0-94e0-b5f6ed166d4d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/67eb86d0-1f10-47a0-94e0-b5f6ed166d4d%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/ZOOwZx5xoCs/unsubscribe](https://groups.google.com/d/topic/elasticsearch/ZOOwZx5xoCs/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/B8FA2C00-FBA6-4550-B839-9D31FF47752D%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/B8FA2C00-FBA6-4550-B839-9D31FF47752D%40pilato.fr)  
> [https://groups.google.com/d/msgid/elasticsearch/B8FA2C00-FBA6-4550-B839-9D31FF47752D%40pilato.fr?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/B8FA2C00-FBA6-4550-B839-9D31FF47752D%40pilato.fr?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--

Regards,  
Sagar Shah

Too many people think more of security instead of opportunity. They seem  
more afraid of life than death!!!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CANZnv5i0MnBn4BCx\_8VX\_%2BAgvdH3OoSQ4vJuV\_juTY35xwLM%2BA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CANZnv5i0MnBn4BCx_8VX_%2BAgvdH3OoSQ4vJuV_juTY35xwLM%2BA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:33am UTC](https://discuss.elastic.co/t/using-filtered-query-with-a-wildcard/22107/4 "2017-07-06T00:33:12Z")

</div>


