Wild Card Queries

(ElasticUsers) #1

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:tst 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).
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.


(system) #2