Search problem with query_string and special characters

Searching with AND operator and special characters with query_string it returns more results than I expect.

Having two documents with one field called searchField, with the next values:

  • First document, value: AAA{BBB}CCC
  • Second document, value: AAA{BBB}DDD

I have the following results:

  • First case: Returns both documents searching for the value: AAA{BBB}CCC
  • Second case: Returns only the first document searching for the value: AAA BBB CCC

I guess both queries should return only the first document as the search is done with AND operator.

The query used in the first case is the following:

"query":{
    "filtered":{
        "query":{
            "bool":{
                "must":[{
                    "query_string":{
                        "query":"AAA\{BBB\}CCC*",
                        "fields":["searchField"],
                        "analyze_wildcard":true,
                        "default_operator":"and"
                    }
                }]
            }
        }
    }
}

I'm using Java with JestClient client.
The reason why I use the bool query is that is created dynamically so it could have more parameters.

This "issue" happens with several special characters. Not sure if I could be doing something wrong.

Thank you very much!

1 Like