1
votes

i have a doubt that how query is search into documents.

When i searched with exact query "what is 1234?" against the keyword analyzed field,i could not get any results. but if i searched "what" against snowball/standard analyzed field then i got some results and i also tried another way to escape space into the query like "what\ is\ 1234?", it also gave some results.

By default what analyzer the query_string will use, whether it will convert user query using any analyzer or it will use what users gave?

please find my gist here: https://gist.github.com/kirubar/6369034

1

1 Answers

1
votes

The reason the query string "what is 1234?" fails to find results isn't the Analyzer, it's the QueryParser.

query_string uses Lucene query syntax. The query parser will interpret that query as three separate queries. That is to say

"query" : "what is 1234?"

Is the equvalent of:

"query" : "what OR is OR 1234?"

If you want to perform a phrase query, it will need to be enclosed on quotes, something like (I beleive you will also need to set the analyzer to a KeywordAnalyzer, so the phrase won't be tokenized, once again preventing matching):

"analyzer" : "keyword",
"query" : "\"what is 1234?\""

Or, better yet, don't even use a query_string query. Instead, use a term query, particularly when querying on a keyword field, like:

"term" : { "message_keyword" : "what is 1234?" }