2013-11-23 66 views
10

我想从我的测试中向ES发送请求。 I applied mapping and inserted documents to ES index named 'gccount_test' from the same test。我在我想测试的名为member的文件中维护一个非常简单的查询。elasticsearch - 没有查询注册为[查询]]

{ 
    "query" : { 
      "match_all" : {} 
    } 
} 

我的测试方法是

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 
    } 

不幸的是,我得到以下错误。

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) 

我使用elasticsearch 0.90.2 dependecy

[group: 'org.elasticsearch', name: 'elasticsearch', version: '0.90.2'] 

同样的事情,运行在真实环境优良(下文快照)

enter image description here

与从同时加载查询问题导致它的畸形的文件或什么?

回答

24

该异常基本上意味着“没有已知的查询类型,称为query”。我猜你的客户端库会自动插入顶级query属性,因此您提出的疑问其实是这样的:

{ 
    "query" : { 
     "query" : { 
      "match_all" : {} 
     } 
    } 
} 

如果您的客户端可以转储查询的JSON表示,这可以帮助在调试中很多。

尝试从您的文本文件中删除query部分,以便它只是match_all查询,看看它是否适合您。

+1

ES还附带验证API,您可以使用它来调试格式错误的查询http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-validate.html – lfender6445