Search in sources :

Example 1 with Action

use of io.searchbox.action.Action in project herd by FINRAOS.

the class IndexFunctionsDaoImpl method getIndexStats.

@Override
public DocsStats getIndexStats(String indexName) {
    Action getStats = new Stats.Builder().addIndex(indexName).build();
    JestResult jestResult = jestClientHelper.executeAction(getStats);
    Assert.isTrue(jestResult.isSucceeded(), jestResult.getErrorMessage());
    JsonObject statsJson = jestResult.getJsonObject().getAsJsonObject("indices").getAsJsonObject(indexName).getAsJsonObject("primaries");
    JsonObject docsJson = statsJson.getAsJsonObject("docs");
    return new DocsStats(docsJson.get("count").getAsLong(), docsJson.get("deleted").getAsLong());
}
Also used : SearchAction(org.elasticsearch.action.search.SearchAction) Action(io.searchbox.action.Action) BulkableAction(io.searchbox.action.BulkableAction) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) JsonObject(com.google.gson.JsonObject) DocsStats(org.elasticsearch.index.shard.DocsStats) JestResult(io.searchbox.client.JestResult)

Example 2 with Action

use of io.searchbox.action.Action in project jmxtrans by jmxtrans.

the class ElasticWriterTests method sendMessageToElasticWriteThrowsException.

@Test(expected = IOException.class)
public void sendMessageToElasticWriteThrowsException() throws Exception {
    // return for call, is index created
    when(mockClient.execute(isA(Action.class))).thenThrow(new IOException("Failed to add index entry to elastic."));
    writer.doWrite(dummyServer(), dummyQuery(), ImmutableList.of(result));
    // only one call is expected: the insert index entry. No write is being made with non-numeric values.
    Mockito.verify(mockClient, times(1)).execute(Matchers.<Action<JestResult>>any());
}
Also used : Action(io.searchbox.action.Action) IOException(java.io.IOException) JestResult(io.searchbox.client.JestResult) Test(org.junit.Test)

Example 3 with Action

use of io.searchbox.action.Action in project herd by FINRAOS.

the class IndexFunctionsDaoImpl method isIndexExists.

@Override
public final boolean isIndexExists(String indexName) {
    Action action = new IndicesExists.Builder(indexName).build();
    JestResult result = jestClientHelper.executeAction(action);
    return result.isSucceeded();
}
Also used : SearchAction(org.elasticsearch.action.search.SearchAction) Action(io.searchbox.action.Action) BulkableAction(io.searchbox.action.BulkableAction) JestResult(io.searchbox.client.JestResult) IndicesExists(io.searchbox.indices.IndicesExists)

Example 4 with Action

use of io.searchbox.action.Action in project herd by FINRAOS.

the class IndexFunctionsDaoImpl method deleteIndex.

/**
 * The delete index function will take as an argument the index name and will delete the index.
 */
@Override
public final void deleteIndex(String indexName) {
    Action action = new DeleteIndex.Builder(indexName).build();
    LOGGER.info("Deleting Elasticsearch index, indexName={}.", indexName);
    JestResult result = jestClientHelper.executeAction(action);
    LOGGER.info("Deleting Elasticsearch index, indexName={}. result successful is {} ", indexName, result.isSucceeded());
}
Also used : SearchAction(org.elasticsearch.action.search.SearchAction) Action(io.searchbox.action.Action) BulkableAction(io.searchbox.action.BulkableAction) DeleteIndex(io.searchbox.indices.DeleteIndex) JestResult(io.searchbox.client.JestResult)

Example 5 with Action

use of io.searchbox.action.Action in project herd by FINRAOS.

the class IndexFunctionsDaoImpl method deleteDocumentById.

/**
 * The delete document by id function will delete a document in the index by the document id.
 */
@Override
public final void deleteDocumentById(String indexName, String documentType, String id) {
    LOGGER.info("Deleting Elasticsearch document from index, indexName={}, documentType={}, id={}.", indexName, documentType, id);
    Action action = new Delete.Builder(id).index(indexName).type(documentType).build();
    JestResult result = jestClientHelper.executeAction(action);
    LOGGER.info("Deleting Elasticsearch document from index, indexName={}, documentType={}, id={} is successfully {}. ", indexName, documentType, id, result.isSucceeded());
}
Also used : Delete(io.searchbox.core.Delete) SearchAction(org.elasticsearch.action.search.SearchAction) Action(io.searchbox.action.Action) BulkableAction(io.searchbox.action.BulkableAction) JestResult(io.searchbox.client.JestResult)

Aggregations

Action (io.searchbox.action.Action)5 JestResult (io.searchbox.client.JestResult)5 BulkableAction (io.searchbox.action.BulkableAction)4 SearchAction (org.elasticsearch.action.search.SearchAction)4 JsonObject (com.google.gson.JsonObject)1 Delete (io.searchbox.core.Delete)1 DeleteIndex (io.searchbox.indices.DeleteIndex)1 IndicesExists (io.searchbox.indices.IndicesExists)1 IOException (java.io.IOException)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 DocsStats (org.elasticsearch.index.shard.DocsStats)1 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)1 Test (org.junit.Test)1