elasticsearch - 没有为 [query]] 注册的查询

2022-09-02 00:31:56

我正在尝试从我的测试向ES发送请求。我应用了映射并将文档插入到来自同一测试的名为“gccount_test”的ES索引中。我在一个名为“我要测试”的文件中维护了一个非常简单的查询。member

{
    "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)

我正在使用弹性搜索 0.90.2 依赖项

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

同样的事情在真实环境中运行良好(下面的快照)

enter image description here

从文件加载查询时的问题是否导致其格式不正确或是什么?


答案 1

异常基本上意味着“没有已知的查询类型称为”。我猜你的客户端库会自动插入顶级属性,所以你生成的查询实际上看起来像这样:queryquery

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

如果您的客户端可以转储查询的 JSON 表示形式,则可以在调试方面提供很多帮助。

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


答案 2

您的查询字符串应为

String query = "{\"match_all\":{}}";

你可以从这里看到

https://discuss.elastic.co/t/parsingexception-in-elastic-5-0-0/64626


推荐