本文整理汇总了Java中org.elasticsearch.client.Response.getEntity方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getEntity方法的具体用法?Java Response.getEntity怎么用?Java Response.getEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.client.Response
的用法示例。
在下文中一共展示了Response.getEntity方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ClientYamlTestResponse
import org.elasticsearch.client.Response; //导入方法依赖的package包/类
ClientYamlTestResponse(Response response) throws IOException {
this.response = response;
if (response.getEntity() != null) {
String contentType = response.getHeader("Content-Type");
this.bodyContentType = XContentType.fromMediaTypeOrFormat(contentType);
try {
byte[] bytes = EntityUtils.toByteArray(response.getEntity());
//skip parsing if we got text back (e.g. if we called _cat apis)
if (bodyContentType != null) {
this.parsedResponse = ObjectPath.createFromXContent(bodyContentType.xContent(), new BytesArray(bytes));
}
this.body = bytes;
} catch (IOException e) {
EntityUtils.consumeQuietly(response.getEntity());
throw e;
}
} else {
this.body = null;
this.bodyContentType = null;
}
}
示例2: perform
import org.elasticsearch.client.Response; //导入方法依赖的package包/类
public SearchResult perform() {
try {
ObjectMapper mapper = new ObjectMapper();
String queryString = serialize();
LOG.info("Query: " + queryString);
Response response = elasticSearchService.getRestClient().performRequest(
"GET",
"/" + index + "/_search",
Collections.<String, String>emptyMap(),
new StringEntity(queryString, "UTF-8"));
HttpEntity entity = response.getEntity();
return mapper.readValue(entity.getContent(), SearchResult.class);
}
catch (IOException ex) {
LOG.error("Could not perform query", ex);
}
return null;
}
示例3: rootRequest
import org.elasticsearch.client.Response; //导入方法依赖的package包/类
public HttpEntity rootRequest() throws IOException {
Response response = restClient.performRequest(
"GET", "/",
Collections.singletonMap("pretty", "true"));
// System.out.println(EntityUtils.toString(response.getEntity()));
return response.getEntity();
}
示例4: refreshIndexes
import org.elasticsearch.client.Response; //导入方法依赖的package包/类
public void refreshIndexes(String... names) {
try {
String endpoint = "/_refresh";
if (names.length > 0) {
endpoint = "/" + String.join(",", names) + endpoint;
}
Response response = client.performRequest(
"POST",
endpoint
);
if (response.getStatusLine().getStatusCode() > 399 && logger.isWarnEnabled()) {
logger.warn("Problem while refreshing indexes: {}", String.join(",", names));
}
if (logger.isDebugEnabled()) {
HttpEntity entity = response.getEntity();
RefreshResponse refreshResponse = jacksonObjectMapper.readValue(entity.getContent(), RefreshResponse.class);
Shards shards = refreshResponse.getShards();
logger.debug("Shards refreshed: total {}, successfull {}, failed {}", shards.getTotal(), shards.getSuccessful(), shards.getFailed());
}
} catch (IOException e) {
logger.warn("Problem while executing refresh request.", e);
throw new ClusterApiException("Error when refreshing indexes." + e.getMessage());
}
}
示例5: checkClusterHealth
import org.elasticsearch.client.Response; //导入方法依赖的package包/类
/**
* Returns the current health of the cluster as a {@link ClusterHealth} object.
*
* @return ClusterHealth containing the basic properties of the health of the cluster
*/
public ClusterHealth checkClusterHealth() {
try {
Response response = client.performRequest(GET, "/_cluster/health");
HttpEntity entity = response.getEntity();
return jacksonObjectMapper.readValue(entity.getContent(), ClusterHealth.class);
} catch (IOException e) {
logger.warn("Problem while executing request.", e);
throw new ClusterApiException("Error when checking the health of the cluster");
}
}
示例6: asMap
import org.elasticsearch.client.Response; //导入方法依赖的package包/类
public static Map<String, Object> asMap(Response response) {
try {
if (response.getEntity() == null) {
return null;
}
return asMap(response.getEntity().getContent());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例7: ElasticsearchResponse
import org.elasticsearch.client.Response; //导入方法依赖的package包/类
public ElasticsearchResponse(Response response) throws IOException {
this.statusLine = response.getStatusLine();
if (response.getEntity() != null) {
this.entity = parseResponse(response);
}
}