Search in sources :

Example 11 with JestResult

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();
    }
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) JestResult(io.searchbox.client.JestResult)

Example 12 with JestResult

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()));
    }
}
Also used : Builder(io.searchbox.core.Bulk.Builder) IOException(java.io.IOException) Bulk(io.searchbox.core.Bulk) JestResult(io.searchbox.client.JestResult)

Example 13 with JestResult

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();
}
Also used : GetAliases(io.searchbox.indices.aliases.GetAliases) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JestResult(io.searchbox.client.JestResult)

Example 14 with JestResult

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());
    }
}
Also used : CreateIndex(io.searchbox.indices.CreateIndex) JestResult(io.searchbox.client.JestResult)

Aggregations

JestResult (io.searchbox.client.JestResult)14 IOException (java.io.IOException)7 Bulk (io.searchbox.core.Bulk)5 Builder (io.searchbox.core.Bulk.Builder)3 CreateIndex (io.searchbox.indices.CreateIndex)3 Test (org.junit.Test)3 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 Result (com.googlecode.jmxtrans.model.Result)2 GsonBuilder (com.google.gson.GsonBuilder)1 OrmException (com.google.gwtorm.server.OrmException)1 Action (io.searchbox.action.Action)1 JestClient (io.searchbox.client.JestClient)1 BulkResult (io.searchbox.core.BulkResult)1 DocumentResult (io.searchbox.core.DocumentResult)1 Index (io.searchbox.core.Index)1 DeleteIndex (io.searchbox.indices.DeleteIndex)1 IndicesExists (io.searchbox.indices.IndicesExists)1 GetAliases (io.searchbox.indices.aliases.GetAliases)1 PutMapping (io.searchbox.indices.mapping.PutMapping)1