gpt4 book ai didi

java - ElasticSearch JavaAPI RestClient 未给出响应

转载 作者:行者123 更新时间:2023-12-02 02:04:17 26 4
gpt4 key购买 nike

我使用 RestClient JavaAPI 从 Elasticsearch 中获取文档。但我的请求没有得到回复。

正在使用 QueryBuilder 形成我的请求。

请找到我用于从 Elasticsearch 获取文档的java代码

private final static String ATTACHMENT = "document_attachment";
private final static String TYPE = "doc";
static long BUFFER_SIZE = 520 * 1024 * 1024; // <---- set buffer to 120MB instead of 100MB

public static void main(String args[])
{
RestClient restClient = null;
Response contentSearchResponse=null;
try {

restClient = RestClient.builder(
new HttpHost("localhost", 9200, "http"),
new HttpHost("localhost", 9201, "http")).build();
} catch (Exception e) {
System.out.println(e.getMessage());
}

SearchRequest contentSearchRequest = new SearchRequest(ATTACHMENT);
SearchSourceBuilder contentSearchSourceBuilder = new SearchSourceBuilder();
contentSearchRequest.types(TYPE);
QueryBuilder attachmentQB = QueryBuilders.matchQuery("attachment.content", "activa");
contentSearchSourceBuilder.query(attachmentQB);
contentSearchSourceBuilder.size(50);
contentSearchRequest.source(contentSearchSourceBuilder);
System.out.println("Request --->"+contentSearchRequest.toString());

Map<String, String> params = Collections.emptyMap();
HttpEntity entity = new NStringEntity(contentSearchSourceBuilder.toString(), ContentType.APPLICATION_JSON);
HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory consumerFactory =
new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory((int) BUFFER_SIZE);

System.out.println("Printing Entity---->"+entity.toString());

try {
contentSearchResponse = restClient.performRequest("GET", "/document_attachment/doc/_search", params, entity, consumerFactory);
} catch (IOException e1) {
e1.printStackTrace();
}
System.out.println("Entity Response --->"+contentSearchResponse.getEntity());
}

请查找使用 Sysout 打印的有关我的请求、实体和响应的详细信息。

Request --->SearchRequest{searchType=QUERY_THEN_FETCH, indices=[document_attachment], indicesOptions=IndicesOptions[id=38, ignore_unavailable=false, allow_no_indices=true, expand_wildcards_open=true, expand_wildcards_closed=false, allow_aliases_to_multiple_indices=true, forbid_closed_indices=true, ignore_aliases=false], types=[doc], routing='null', preference='null', requestCache=null, scroll=null, maxConcurrentShardRequests=0, batchedReduceSize=512, preFilterShardSize=128, source={"size":50,"query":{"match":{"id":{"query":"87740","operator":"OR","prefix_length":0,"max_expansions":50,"fuzzy_transpositions":true,"lenient":false,"zero_terms_query":"NONE","auto_generate_synonyms_phrase_query":true,"boost":1.0}}}}}
Printing Entity---->[Content-Type: application/json; charset=UTF-8,Content-Length: 233,Chunked: false]
Entity Response --->[Content-Length: 929382,Chunked: false]

最佳答案

您确实收到了 929382 字节长的响应。因此,您只需从响应中读取数据即可:

String responseBody = EntityUtils.toString(response.getEntity());

关于java - ElasticSearch JavaAPI RestClient 未给出响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51039930/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com