从文件创建响应elasticsearch响应时出错

jmo0nnb3  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(1)|浏览(401)

我尝试从文件中创建响应来测试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,是否有其他方法来创建响应或者我在哪里犯了错误?

06odsfpq

06odsfpq1#

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

第一行的bufferedinputstream在传递给readfrom之前被转换为streaminput

相关问题