# Wild Card Queries

**URL:** <https://discuss.elastic.co/t/wild-card-queries/7822>\
**Category:** Elasticsearch\
**Created:** [May 23, 2012, 11:59am UTC](https://discuss.elastic.co/t/wild-card-queries/7822 "2012-05-23T11:59:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticUsers](https://avatars.discourse-cdn.com/v4/letter/e/51bf81/32.png) [@ElasticUsers](https://discuss.elastic.co/u/ElasticUsers)\
**Post date:** [May 23, 2012, 11:59am UTC](https://discuss.elastic.co/t/wild-card-queries/7822/1 "2012-05-23T11:59:25Z")

</div>

Hi Team,

I am indexing a field 'message' using standard analyzer. Suppose we index a sentence "This is test" under message field. When I query like message:test\* or message:_test I am getting back docs but when I query like message:t_st or message:t?st , no docs are returned.

Given below is the code snippet for search query :

String queryString=""....  
QueryBuilder qb=....  
if (queryString !=null && !queryString.equals("")) {  
qb = QueryBuilders.queryString(queryString).defaultOperator(Operator.AND).  
allowLeadingWildcard(false).analyzer(getDefaultAnalyzer()).analyzeWildcard(true);  
}else{  
qb = QueryBuilders.matchAllQuery();  
}

I am escaping \* and ? before forming the query string so that queryString becomes something like message:test\*, message:\*test or message:t?st.

Explanation obtained from SearchResponse shows that in case of queries message:test\* and message:\*test the \* is removed and search is performed only for message:test, message:test. But this behavior is not consistent while executing queries like message:t?st, \* and ? not removed during analysis process.

Can you please let me know the cause for this inconsistent behavior and any solution.

Thanks

---

<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, 3:27am UTC](https://discuss.elastic.co/t/wild-card-queries/7822/2 "2017-07-06T03:27:32Z")

</div>


