use of org.elasticsearch.client.Request in project janusgraph by JanusGraph.
the class RestElasticSearchClient method countTotal.
@Override
public long countTotal(String indexName, Map<String, Object> requestData) throws IOException {
final Request request = new Request(REQUEST_TYPE_GET, REQUEST_SEPARATOR + indexName + REQUEST_SEPARATOR + "_count");
final byte[] requestDataBytes = mapper.writeValueAsBytes(requestData);
if (log.isDebugEnabled()) {
log.debug("Elasticsearch request: " + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(requestData));
}
final Response response = performRequest(request, requestDataBytes);
try (final InputStream inputStream = response.getEntity().getContent()) {
return mapper.readValue(inputStream, RestCountResponse.class).getCount();
}
}
use of org.elasticsearch.client.Request in project janusgraph by JanusGraph.
the class RestElasticSearchClient method createStoredScript.
@Override
public void createStoredScript(String scriptName, Map<String, Object> script) throws IOException {
Request request = new Request(REQUEST_TYPE_POST, REQUEST_SEPARATOR + "_scripts" + REQUEST_SEPARATOR + scriptName);
performRequest(request, mapWriter.writeValueAsBytes(script));
}
use of org.elasticsearch.client.Request in project janusgraph by JanusGraph.
the class RestElasticSearchClient method search.
private RestSearchResponse search(Map<String, Object> requestData, String path) throws IOException {
final Request request = new Request(REQUEST_TYPE_POST, path);
final byte[] requestDataBytes = mapper.writeValueAsBytes(requestData);
if (log.isDebugEnabled()) {
log.debug("Elasticsearch request: " + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(requestData));
}
final Response response = performRequest(request, requestDataBytes);
try (final InputStream inputStream = response.getEntity().getContent()) {
return mapper.readValue(inputStream, RestSearchResponse.class);
}
}
use of org.elasticsearch.client.Request in project janusgraph by JanusGraph.
the class RestElasticSearchClient method clusterHealthRequest.
@Override
public void clusterHealthRequest(String timeout) throws IOException {
Request clusterHealthRequest = new Request(REQUEST_TYPE_GET, REQUEST_SEPARATOR + "_cluster" + REQUEST_SEPARATOR + "health");
clusterHealthRequest.addParameter("wait_for_status", "yellow");
clusterHealthRequest.addParameter("timeout", timeout);
final Response response = delegate.performRequest(clusterHealthRequest);
try (final InputStream inputStream = response.getEntity().getContent()) {
final Map<String, Object> values = mapReader.readValue(inputStream);
if (!values.containsKey("timed_out")) {
throw new IOException("Unexpected response for Elasticsearch cluster health request");
} else if (!Objects.equals(values.get("timed_out"), false)) {
throw new IOException("Elasticsearch timeout waiting for yellow status");
}
}
}
use of org.elasticsearch.client.Request in project janusgraph by JanusGraph.
the class RestElasticSearchClient method createMapping.
@Override
public void createMapping(String indexName, String typeName, Map<String, Object> mapping) throws IOException {
Request request;
if (useMappingTypes) {
request = new Request(REQUEST_TYPE_PUT, REQUEST_SEPARATOR + indexName + REQUEST_SEPARATOR + "_mapping" + REQUEST_SEPARATOR + typeName);
if (esVersion7) {
request.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true");
}
} else {
request = new Request(REQUEST_TYPE_PUT, REQUEST_SEPARATOR + indexName + REQUEST_SEPARATOR + "_mapping");
}
performRequest(request, mapWriter.writeValueAsBytes(mapping));
}
Aggregations