use of io.searchbox.client.JestResult in project spring-boot by spring-projects.
the class ElasticsearchJestHealthIndicator method doHealthCheck.
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
JestResult aliases = this.jestClient.execute(new Stats.Builder().build());
JsonElement root = this.jsonParser.parse(aliases.getJsonString());
JsonObject shards = root.getAsJsonObject().get("_shards").getAsJsonObject();
int failedShards = shards.get("failed").getAsInt();
if (failedShards != 0) {
builder.outOfService();
} else {
builder.up();
}
}
use of io.searchbox.client.JestResult in project gerrit by GerritCodeReview.
the class ElasticGroupIndex method replace.
@Override
public void replace(AccountGroup group) throws IOException {
Bulk bulk = new Bulk.Builder().defaultIndex(indexName).defaultType(GROUPS).addAction(insert(GROUPS, group)).refresh(true).build();
JestResult result = client.execute(bulk);
if (!result.isSucceeded()) {
throw new IOException(String.format("Failed to replace group %s in index %s: %s", group.getGroupUUID().get(), indexName, result.getErrorMessage()));
}
}
use of io.searchbox.client.JestResult in project gerrit by GerritCodeReview.
the class ElasticIndexVersionDiscovery method discover.
List<String> discover(String prefix, String indexName) throws IOException {
String name = prefix + indexName + "_";
JestResult result = client.execute(new GetAliases.Builder().addIndex(name + "*").build());
if (result.isSucceeded()) {
JsonObject object = result.getJsonObject().getAsJsonObject();
List<String> versions = new ArrayList<>(object.size());
for (Entry<String, JsonElement> entry : object.entrySet()) {
versions.add(entry.getKey().replace(name, ""));
}
return versions;
}
return Collections.emptyList();
}
use of io.searchbox.client.JestResult in project opennms by OpenNMS.
the class EventToIndex method createIndex.
private static void createIndex(JestClient client, String name, String type) throws IOException {
// create new index
CreateIndex createIndex = new CreateIndex.Builder(name).build();
JestResult result = new OnmsJestResult(client.execute(createIndex));
if (LOG.isDebugEnabled()) {
LOG.debug("created new alarm index: {} type: {}" + "\n received search result: {}" + "\n response code: {}" + "\n error message: {}", name, type, result.getJsonString(), result.getResponseCode(), result.getErrorMessage());
}
}
Aggregations