I am pretty new to elasticsearch and just need some clarification: Can we define a analyzer while querying the search server. I tried it with the "text" and "field" query and it works fine:
Query:
curl -XPOST http://localhost:9200/test/user/_search? -d '{ "query" : { "text" : {"_all" : {"query" :"Vaibhav","analyzer" : "lowercase_keyword" }} } }'
Result:
{"took":144,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.10848885,"hits":{"_index":"test","_type":"user","_id":"1","_score":0.10848885, "_source" : { "first_name": "Vaibhav", "last_name":"saini", "password":"pwd"
But when I try to do the same thing with term/prefix/wildcard query I get the exception:
Query:
curl -XPOST http://localhost:9200/test/user/_search? -d '{ "query" : { "term" : {"_all" : {"query" :"Vaibhav","analyzer" : "lowercase_keyword" }} } }'
Result:
{"error":"SearchPhaseExecutionException[Failed to execute phase [query], total failure; shardFailures {[kws9J6tbQtWCMNKBm3Gpkw][test][4]: SearchParseException[[test][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [\n{\n\"query\" : {\n\"term\" : {\"_all\" : {\"query\" :\"Vaibhav\",\"analyzer\" : \"lowercase_keyword\" }}\n}\n}]]]; nested: QueryParsingException[[test] [term] query does not support [query]]; }{[kws9J6tbQtWCMNKBm3Gpkw][test][1]: SearchParseException[[test][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [\n{\n\"query\" : {\n\"term\" : {\"_all\" : {\"query\" :\"Vaibhav\",\"analyzer\" : \"lowercase_keyword\" }}\n}\n}]]]; nested: QueryParsingException[[test] [term] query does not support [query]]; }{[kws9J6tbQtWCMNKBm3Gpkw][test][2]: SearchParseException[[test][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [\n{\n\"query\" : {\n\"term\" : {\"_all\" : {\"query\" :\"Vaibhav\",\"analyzer\" : \"lowercase_keyword\" }}\n}\n}]]]; nested: QueryParsingException[[test] [term] query does not support [query]]; }]","status":500}
So is it like we can't define analayzers while querying the elasticsearch server for some type of queries and for others we can? If not, am I doing anything wrong?
Any help is greatly appreciated.
The term
, prefix
, and wildcard
queries expect the value specified in the query to be already analyzed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With