弹性搜索 - 没有查询注册[查询]] [英] elasticsearch - No query registered for [query]]
问题描述
我正在尝试从ES测试发送请求。 我将映射和插入的文档应用于名为 gccount_test'来自同一测试。我有一个非常简单的查询,保存在我想要测试的名为成员
的文件中。
code> {
query:{
match_all:{}
}
}
我的测试方法是
public void testMemberQuery(){
final Charset CHARSET = StandardCharsets.UTF_8
//加载查询
byte [] bytes = Files.readAllBytes(Paths.get(MEMBER_QUERY_PATH))
String query = CHARSET。解码(ByteBuffer.wrap(bytes))toString()
printlnQUERY => $ {query}
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder()
searchSourceBuilder.query(query)
SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX_NAME)
// ClusterAdminClient adminClient = client.admin()。cluster()
// searchRequestBuilder。 setTypes(Constants.ESTYPE_MEMBER)
// println CLUSTER => $ {adminClient}
searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH);
searchRequestBuilder.internalBuilder(searchSourceBuilder)
SearchResponse searchResponse = searchRequestBuilder.execute()。actionGet ()
printlnSearch Response => $ {searchResponse.toString()}
// blah blah
}
不幸的是,我收到以下错误。
无法执行阶段[query_fetch],完全失败; shardFailures {[ 1] [gccount] [0]:SearchParseException [[gccount_test] [0]:from [-1],size [-1]:Parse Failure [无法解析源[{查询_ ]];嵌套:QueryParsingException [[gccount_test]没有为[query]]注册查询];
org.elasticsearch.action.search.SearchPhaseExecutionException:执行阶段[query_fetch]失败,总失败; shardFailures {[1] [gccount_test] [0]:SearchParseException [[gccount_test] [0]:from [-1],size [-1]:Parse Failure [无法解析源[{查询_ ;嵌套:QueryParsingException [[gccount_test]没有查询[query]];}
在org.elasticse arch.action.search.type.TransportSearchTypeAction $ BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:261)
在org.elasticsearch.action.search.type.TransportSearchTypeAction $ BaseAsyncAction $ 3.onFailure(TransportSearchTypeAction.java:214)
在org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteFetch(SearchServiceTransportAction.java:246)
在org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction $ AsyncAction.sendExecuteFirstPhase(TransportSearchQueryAndFetchAction.java:75)
在org.elasticsearch.action.search.type.TransportSearchTypeAction $ BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:206)
在org.elasticsearch.action.search.type.TransportSearchTypeAction $ BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java: 193)
在org.elasticsearch.action.search.type.TransportSearchTypeAction $ BaseAsyncAction $ 2.run(TransportSearchTypeAction.java:179)
在java.util.conc urrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:603)
在java.lang.Thread.run(Thread。 java:722)
我正在使用弹性搜索0.90.2依赖
[group:'org.elasticsearch',name:'elasticsearch',version:'0.90.2']
/ pre>
相同的事情在真实环境中运行正常(下面的快照)
从文件加载查询时导致它的问题畸形或什么?
解决方案异常基本意味着没有已知的查询类型称为
查询
。我猜测您的客户端库自动插入顶层
查询
属性,因此您生成的查询实际上如下所示:{
查询:{
查询:{
match_all:{}
}
}
}
如果您的客户端可以转储查询的JSON表示,那么可以帮助很多调试。
尝试从您的文本文件中删除
查询
部分,以便它只是match_all
查询,看看是否适用于您。I am trying to send request to ES from my tests. I applied mapping and inserted documents to ES index named 'gccount_test' from the same test. I have a very simple query maintained in a file named
member
that I want to test.{ "query" : { "match_all" : {} } }
My test method is
public void testMemberQuery(){ final Charset CHARSET = StandardCharsets.UTF_8 //load query byte[] bytes = Files.readAllBytes(Paths.get(MEMBER_QUERY_PATH)) String query = CHARSET.decode(ByteBuffer.wrap(bytes)).toString() println "QUERY => ${query}" SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder() searchSourceBuilder.query(query) SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX_NAME) //ClusterAdminClient adminClient = client.admin().cluster() //searchRequestBuilder.setTypes(Constants.ESTYPE_MEMBER) //println "CLUSTER => ${adminClient}" searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH); searchRequestBuilder.internalBuilder(searchSourceBuilder) SearchResponse searchResponse = searchRequestBuilder.execute().actionGet() println "Search Response => ${searchResponse.toString()}" //blah blah }
Unfortunately, I get following error.
Failed to execute phase [query_fetch], total failure; shardFailures {[1][gccount][0]: SearchParseException[[gccount_test][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query_binary":"ewogICAgInF1ZXJ5IiA6IHsgCiAgICAgICAgICAibWF0Y2hfYWxsIiA6IHt9IAogICAgIH0KfQ=="}]]]; nested: QueryParsingException[[gccount_test] No query registered for [query]]; } org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to execute phase [query_fetch], total failure; shardFailures {[1][gccount_test][0]: SearchParseException[[gccount_test][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query_binary":"ewogICAgInF1ZXJ5IiA6IHsgCiAgICAgICAgICAibWF0Y2hfYWxsIiA6IHt9IAogICAgIH0KfQ=="}]]]; nested: QueryParsingException[[gccount_test] No query registered for [query]]; } at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:261) at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onFailure(TransportSearchTypeAction.java:214) at org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteFetch(SearchServiceTransportAction.java:246) at org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryAndFetchAction.java:75) at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:206) at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:193) at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:179) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)
I am using elasticsearch 0.90.2 dependecy
[group: 'org.elasticsearch', name: 'elasticsearch', version: '0.90.2']
Same thing runs fine in real environment(snapshot below)
Is the problem with while loading query from file that caused it's malformation or what?
解决方案The exception basically means "There is no known query type called
query
". I'm guessing that your client library is automatically inserting the top-levelquery
property, so your generated query actually looks like this:{ "query" : { "query" : { "match_all" : {} } } }
If your client can dump the JSON representation of the query, that can help a lot in debugging.
Try removing the
query
portion from your text file so that it is just thematch_all
query, see if that works for you.这篇关于弹性搜索 - 没有查询注册[查询]]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!