在elasticSearch中查询时定义分析器 [英] Defining analyzer while querying in elasticSearch

查看:444
本文介绍了在elasticSearch中查询时定义分析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常喜欢弹性搜索,只需要一些澄清:
我们可以在查询搜索服务器时定义分析器。我尝试使用文本和字段查询,它工作正常:



查询:

  curl -XPOST http:// localhost:9200 / test / user / _search? -d'{query:{
text:{_all:{query:Vaibhav,analyzer:
lowercase_keyword}}}}'

结果:

  { 花:144, TIMED_OUT:假, _碎片:{ 总:5, 成功:5, 失败:0}, 命中:{ 总:1, max_score:0.10848885,hits:{_ index:test,_ type:user,_ id:1,_ score:0.10848885,
_source
first_name:Vaibhav,
last_name:saini,
password:pwd

但是当我尝试用term / prefix / wildcard查询做同样的事情时,我得到例外:



查询:

  curl -XPOST http:// localhost:9200 / test / user / _search? -d'{
query:{term:{_all:{query:Vaibhav,analyzer:
lowercase_keyword}}}}'

结果:

  {error:SearchPhaseExecutionException [执行阶段[查询]失败,完全失败; shardFailures 
{[kws9J6tbQtWCMNKBm3Gpkw] [test] [4]:SearchParseException [[test] [4]:
从[-1],size [-1]:解析失败[无法解析源
[\\\
{\\\
\query\:{\\\
\term\ :{\_all\:{\query\
:\Vaibhav\,\analyzer\:\lowercase_keyword\}} \ n} \\\
}]];嵌套:
QueryParsingException [[test] [term] query不支持[query]];
} {[kws9J6tbQtWCMNKBm3Gpkw] [test] [1]:SearchParseException [[test] [1]:
from [-1],size [-1]:Parse Failure [无法解析源
[\\\
{\\\
\query\ :{\\\
\term\:{\_all\:{\query\
:\Vaibhav\ ,\analyzer\:\lowercase_keyword\}} \\\
} \\\
}]];嵌套:
QueryParsingException [[test] [term]查询不支持[查询]];
} {[kws9J6tbQtWCMNKBm3Gpkw] [test] [2]:SearchParseException [[test] [2]:
from [-1],size [-1]:Parse Failure [无法解析源
[\\\
{\\\
\query\:{\\\
\term\:{\_all\:{\query\
:\Vaibhav\,\analyzer\:\lowercase_keyword\}} \\\
} \\\
}]]];嵌套:
QueryParsingException [[test] [term]查询不支持[query]];
}],状态:500}

在查询弹性搜索服务器进行某些类型的查询时,我们可以定义分析器,而对于其他类型的查询,如果没有,我做错了什么?



任何帮助都非常感谢。 / p>

解决方案

术语前缀通配符查询期望查询中指定的值已被分析。


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.

这篇关于在elasticSearch中查询时定义分析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆