@Override public ActionResponse get() { return requestBuilder.get(); }
@Override public ActionRequest request() { return requestBuilder.request(); }
@Override public ActionRequestValidationException validate() { if (configTypes == null || configTypes.length == 0) { return new ActionRequestValidationException(); } return null; } }
@Override public void execute() throws Exception { try { BulkResponse bulkResponse = bulkRequestBuilder.execute().actionGet(); if (bulkResponse.hasFailures()) { throw new EventDeliveryException(bulkResponse.buildFailureMessage()); } } finally { bulkRequestBuilder = client.prepareBulk(); } }
@Override public SearchResponse get() { Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start(); try { return super.execute().actionGet(); } catch (Exception e) { throw new IllegalStateException(String.format("Fail to execute %s", toString()), e); } finally { if (profiler.isTraceEnabled()) { profiler.stopTrace(toString()); } } }
private SearchResponse getSearchResponse(ElasticsearchQueryBuilder queryBuilder) { try { return retry() .maxAttempts(maxAttempts) .exponentialBackoff(maxRetryTime) .run("searchRequest", () -> queryBuilder.buildScrollSearchRequest() .execute() .actionGet(requestTimeout.toMillis())); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public IndexResponse get() { Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start(); try { return super.execute().actionGet(); } catch (Exception e) { throw new IllegalStateException(String.format("Fail to execute %s", toString()), e); } finally { if (profiler.isTraceEnabled()) { profiler.stopTrace(toString()); } } }
/** * Read a json document from the search index for a given id. * Elasticsearch reads the '_source' field and parses the content as json. * * @param id * the unique identifier of a document * @return the document as json, matched on a Map<String, Object> object instance */ public Map<String, Object> readMap(String indexName, final String id) { GetResponse response = elasticsearchClient.prepareGet(indexName, null, id).execute().actionGet(); Map<String, Object> map = getMap(response); return map; }
@Override public PutMappingResponse get() { Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start(); try { return super.execute().actionGet(); } catch (Exception e) { throw new IllegalStateException(String.format("Fail to execute %s", toString()), e); } finally { if (profiler.isTraceEnabled()) { profiler.stopTrace(toString()); } } }
@Override public SearchResponse get() { Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start(); try { return super.execute().actionGet(); } catch (Exception e) { throw new IllegalStateException(String.format("Fail to execute %s", toString()), e); } finally { if (profiler.isTraceEnabled()) { profiler.stopTrace(toString()); } } }
@Override public DeleteResponse get() { Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start(); try { return super.execute().actionGet(); } catch (Exception e) { throw new IllegalStateException(String.format("Fail to execute %s", toString()), e); } finally { if (profiler.isTraceEnabled()) { profiler.stopTrace(toString()); } } }
/** * Verify the results in an Elasticsearch index. The results must first be produced into the index * using a {@link TestElasticsearchSinkFunction}; * * @param client The client to use to connect to Elasticsearch * @param index The index to check */ public static void verifyProducedSinkData(Client client, String index) { for (int i = 0; i < NUM_ELEMENTS; i++) { GetResponse response = client.get(new GetRequest(index, TYPE_NAME, Integer.toString(i))).actionGet(); Assert.assertEquals(DATA_PREFIX + i, response.getSource().get(DATA_FIELD_NAME)); } }
private SearchResponse getScrollResponse(ElasticsearchQueryBuilder queryBuilder, String scrollId) { try { return retry() .maxAttempts(maxAttempts) .exponentialBackoff(maxRetryTime) .run("scrollRequest", () -> queryBuilder.prepareSearchScroll(scrollId) .execute() .actionGet(requestTimeout.toMillis())); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public GetResponse get(GetRequest getRequest) throws IOException { try { return transportClient.get(getRequest).get(); } catch (Exception e) { throw new IOException(e); } }
private BulkRequestBuilder initRequest() { BulkRequestBuilder bulkRequest = client.prepareBulk(); bulkRequest.setConsistencyLevel( WriteConsistencyLevel.fromString( config.getWriteConsistencyLevel() ) ); bulkRequest.setRefresh( config.isForcedRefresh() ); return bulkRequest; }
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeString(dn); out.writeBoolean(isAdmin); out.writeBoolean(isAuthenticated); out.writeBoolean(isNodeCertificateRequest); }
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); dn = in.readString(); isAdmin = in.readBoolean(); isAuthenticated = in.readBoolean(); isNodeCertificateRequest = in.readBoolean(); }
private ClusterSearchShardsResponse getSearchShardsResponse(TransportClient client, ClusterSearchShardsRequest request) { try { return retry() .maxAttempts(maxAttempts) .exponentialBackoff(maxRetryTime) .run("getSearchShardsResponse", () -> client.admin() .cluster() .searchShards(request) .actionGet(requestTimeout.toMillis())); } catch (Exception e) { throw new RuntimeException(e); } }