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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20167976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 23:40:04  来源:igfitidea点击:

elasticsearch - No query registered for [query]]

javagroovyelasticsearch

提问by prayagupd

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 memberthat I want to test.

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

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

我正在使用 elasticsearch 0.90.2 依赖

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

Same thing runs fine in real environment(snapshot below)

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

enter image description here

在此处输入图片说明

Is the problem with while loading query from file that caused it's malformation or what?

从文件加载查询时是否有问题导致其格式错误或什么?

采纳答案by Zach

The exception basically means "There is no known query type called query". I'm guessing that your client library is automatically inserting the top-level queryproperty, so your generated query actually looks like this:

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

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

If your client can dump the JSON representation of the query, that can help a lot in debugging.

如果您的客户端可以转储查询的 JSON 表示,则对调试有很大帮助。

Try removing the queryportion from your text file so that it is just the match_allquery, see if that works for you.

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

回答by riverfan

your query string should be

您的查询字符串应该是

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

you can see from here

你可以从这里看到

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

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