有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

从文件创建响应elasticsearch响应时发生java错误

我尝试从文件中创建响应以测试elasticsearch服务

    def "FounderHint"() {
        setup:
        URL url = getClass().getClassLoader().getResource("elastic_response/elastic-founders-hint-response.json")
        SearchResponse response = new SearchResponse().readFrom(url.openStream())  // this is a 40 line error

        when: "we ask for hint"
        elasticClient.search(any()) >> response
        metrics.measureHintSearchTime(_) >> response

        then: "we get list of ObjectHint"
        List<ObjectHint> result = advancedSearchFilter.founderHint("але").collect(Collectors.toList())

        result[0].inn == "323500905646"
        result[0].name == "Алешина Екатерина Леонидовна"

但我有一个错误-

No signature of method: org.elasticsearch.action.search.SearchResponse.readFrom() is applicable for argument types: (java.io.BufferedInputStream) values: [java.io.BufferedInputStream@19f135ca]
Possible solutions: readFrom(org.elasticsearch.common.io.stream.StreamInput), readFrom(org.elasticsearch.common.io.stream.StreamInput), readFrom(org.elasticsearch.common.io.stream.StreamInput)
groovy.lang.MissingMethodException: No signature of method: org.elasticsearch.action.search.SearchResponse.readFrom() is applicable for argument types: (java.io.BufferedInputStream) values: [java.io.BufferedInputStream@19f135ca]
Possible solutions: readFrom(org.elasticsearch.common.io.stream.StreamInput), readFrom(org.elasticsearch.common.io.stream.StreamInput), readFrom(org.elasticsearch.common.io.stream.StreamInput)
    at ru.esphere.informator.refbook.retriever.hint.SearchExternalHintServiceTest.test external hint method for receive correct result(SearchExternalHintServiceTest.groovy:40)

SearchResponse是一个类elasticsearch,它没有setter,是否有其他方法来创建响应,或者我在哪里犯了错误


共 (1) 个答案

  1. # 1 楼答案

        BufferedInputStream stream = url.openStream()
        SearchResponse response = new SearchResponse().readFrom(new StreamInput(stream))
    

    来自第一行的BufferedInputStream在传递给readFrom之前被转换为StreamInput