org.elasticsearch.action.ActionRequestBuilder Java Examples
The following examples show how to use
org.elasticsearch.action.ActionRequestBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultiQueryAction.java From foxtrot with Apache License 2.0 | 6 votes |
@Override public MultiSearchRequestBuilder getRequestBuilder(MultiQueryRequest parameter) { MultiSearchRequestBuilder multiSearchRequestBuilder = getConnection().getClient() .prepareMultiSearch(); for(Map.Entry<String, ActionRequest> entry : parameter.getRequests() .entrySet()) { ActionRequest request = entry.getValue(); Action<ActionRequest> action = analyticsLoader.getAction(request); if(null == action) { throw FoxtrotExceptions.queryCreationException(request, null); } ActionRequestBuilder requestBuilder = action.getRequestBuilder(request); if(requestBuilder instanceof SearchRequestBuilder) { multiSearchRequestBuilder.add((SearchRequestBuilder)requestBuilder); } } return multiSearchRequestBuilder; }
Example #2
Source File: ElasticsearchAssertions.java From crate with Apache License 2.0 | 6 votes |
/** * Executes the request and fails if the request has not been blocked by a specific {@link ClusterBlock}. * * @param builder the request builder * @param expectedBlock the expected block */ public static void assertBlocked(ActionRequestBuilder builder, ClusterBlock expectedBlock) { try { builder.get(); fail("Request executed with success but a ClusterBlockException was expected"); } catch (ClusterBlockException e) { assertThat(e.blocks().size(), greaterThan(0)); assertThat(e.status(), equalTo(RestStatus.FORBIDDEN)); if (expectedBlock != null) { boolean found = false; for (ClusterBlock clusterBlock : e.blocks()) { if (clusterBlock.id() == expectedBlock.id()) { found = true; break; } } assertThat("Request should have been blocked by [" + expectedBlock + "] instead of " + e.blocks(), found, equalTo(true)); } } }
Example #3
Source File: TermsByQueryBenchmark.java From siren-join with GNU Affero General Public License v3.0 | 6 votes |
public long runQuery(String name, int testNum, long expectedHits, ActionRequestBuilder request) { long timestamp = System.nanoTime(); TermsByQueryResponse response = (TermsByQueryResponse) request.execute().actionGet(); long timeElapsed = System.nanoTime() - timestamp; if (response.getFailedShards() > 0) { log("Search Failures " + Arrays.toString(response.getShardFailures())); } long hits = response.getSize(); if (MAX_TERMS_PER_SHARD == -1 && hits != expectedHits) { log("[" + name + "][#" + testNum + "] Hits Mismatch: expected [" + expectedHits + "], got [" + hits + "]"); } return timeElapsed / 1000000; }
Example #4
Source File: ElasticsearchClientImpl.java From herd with Apache License 2.0 | 5 votes |
@Override public <RequestT extends ActionRequest, ResponseT extends ActionResponse, RequestBuilderT extends ActionRequestBuilder<RequestT, ResponseT, RequestBuilderT>> void execute( Action<RequestT, ResponseT, RequestBuilderT> action, RequestT request, ActionListener<ResponseT> actionListener) { // stub method }
Example #5
Source File: HttpInvoker.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void doExecute(Action<Request, Response, RequestBuilder> action, Request request, ActionListener<Response> listener) { HttpElasticsearchClient.ActionEntry entry = actionMap.get(action.name()); if (entry == null) { throw new IllegalStateException("no action entry for " + action.name()); } HttpAction<Request, Response> httpAction = entry.httpAction; if (httpAction == null) { throw new IllegalStateException("failed to find action [" + action + "] to execute"); } HttpInvocationContext<Request, Response> httpInvocationContext = new HttpInvocationContext(httpAction, listener, new LinkedList<>(), request); try { httpInvocationContext.httpRequest = httpAction.createHttpRequest(this.url, request); } catch (IOException e) { logger.error(e.getMessage(), e); } ChannelFuture future = bootstrap.connect(new InetSocketAddress(url.getHost(), url.getPort())); future.awaitUninterruptibly(); if (!future.isSuccess()) { bootstrap.releaseExternalResources(); logger.error("can't connect to {}", url); } else { Channel channel = future.getChannel(); httpInvocationContext.setChannel(channel); contexts.put(channel, httpInvocationContext); channel.getConfig().setConnectTimeoutMillis(settings.getAsInt("http.client.timeout", 5000)); httpAction.execute(httpInvocationContext, listener); } }
Example #6
Source File: HttpElasticsearchClient.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void doExecute(Action<Request, Response, RequestBuilder> action, Request request, ActionListener<Response> listener) { ActionEntry entry = actionMap.get(action.name()); if (entry == null) { throw new IllegalStateException("no action entry for " + action.name()); } HttpAction<Request, Response> httpAction = entry.httpAction; if (httpAction == null) { throw new IllegalStateException("failed to find action [" + action + "] to execute"); } HttpInvocationContext<Request, Response> httpInvocationContext = new HttpInvocationContext(httpAction, listener, new LinkedList<>(), request); try { httpInvocationContext.httpRequest = httpAction.createHttpRequest(this.url, request); } catch (IOException e) { logger.error(e.getMessage(), e); } ChannelFuture future = bootstrap.connect(new InetSocketAddress(url.getHost(), url.getPort())); future.awaitUninterruptibly(); if (!future.isSuccess()) { bootstrap.releaseExternalResources(); logger.error("can't connect to {}", url); } else { Channel channel = future.getChannel(); httpInvocationContext.setChannel(channel); contextMap.put(channel, httpInvocationContext); channel.getConfig().setConnectTimeoutMillis(settings.getAsInt("http.client.timeout", 5000)); httpAction.execute(httpInvocationContext, listener); } }
Example #7
Source File: AbstractClient.java From crate with Apache License 2.0 | 5 votes |
@Override public final <Request extends TransportRequest, Response extends TransportResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> ActionFuture<Response> execute( Action<Request, Response, RequestBuilder> action, Request request) { PlainActionFuture<Response> actionFuture = PlainActionFuture.newFuture(); execute(action, request, actionFuture); return actionFuture; }
Example #8
Source File: NodeClient.java From crate with Apache License 2.0 | 5 votes |
@Override public <Request extends TransportRequest, Response extends TransportResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void doExecute( Action<Request, Response, RequestBuilder> action, Request request, ActionListener<Response> listener) { // Discard the task because the Client interface doesn't use it. executeLocally(action, request, listener); }
Example #9
Source File: ElasticsearchClientImpl.java From herd with Apache License 2.0 | 5 votes |
@Override public <RequestT extends ActionRequest, ResponseT extends ActionResponse, RequestBuilderT extends ActionRequestBuilder<RequestT, ResponseT, RequestBuilderT>> RequestBuilderT prepareExecute( Action<RequestT, ResponseT, RequestBuilderT> action) { return null; }
Example #10
Source File: ElasticsearchClientImpl.java From herd with Apache License 2.0 | 5 votes |
@Override public <RequestT extends ActionRequest, ResponseT extends ActionResponse, RequestBuilderT extends ActionRequestBuilder<RequestT, ResponseT, RequestBuilderT>> ActionFuture<ResponseT> execute( Action<RequestT, ResponseT, RequestBuilderT> action, RequestT request) { return null; }
Example #11
Source File: ElasticsearchIndex.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static long doUpdateRequest(ActionRequestBuilder<?, ? extends UpdateResponse, ?> request) throws IOException { UpdateResponse response = request.execute().actionGet(); boolean isUpsert = response.status().equals(RestStatus.CREATED); if (isUpsert) { throw new IOException("Unexpected upsert: " + request.get().getClass().getName()); } return response.getVersion(); }
Example #12
Source File: ElasticsearchIndex.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static long doIndexRequest(ActionRequestBuilder<?, ? extends IndexResponse, ?> request) throws IOException { IndexResponse response = request.execute().actionGet(); boolean ok = response.status().equals(RestStatus.CREATED); if (!ok) { throw new IOException("Document not created: " + request.get().getClass().getName()); } return response.getVersion(); }
Example #13
Source File: ElasticsearchIndex.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void doAcknowledgedRequest(ActionRequestBuilder<?, ? extends AcknowledgedResponse, ?> request) throws IOException { boolean ok = request.execute().actionGet().isAcknowledged(); if (!ok) { throw new IOException("Request not acknowledged: " + request.get().getClass().getName()); } }
Example #14
Source File: ElasticsearchAssertions.java From crate with Apache License 2.0 | 4 votes |
/** * Run the request from a given builder and check that it throws an exception of the right type */ public static <E extends Throwable> void assertThrows(ActionRequestBuilder<?, ?, ?> builder, Class<E> exceptionClass) { assertThrows(builder.execute(), exceptionClass); }
Example #15
Source File: MultiTimeQueryAction.java From foxtrot with Apache License 2.0 | 4 votes |
@Override public ActionRequestBuilder getRequestBuilder(MultiTimeQueryRequest parameter) { return action.getRequestBuilder(multiQueryRequest); }
Example #16
Source File: AbstractClient.java From crate with Apache License 2.0 | 4 votes |
@Override public <Request extends TransportRequest, Response extends TransportResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void execute( Action<Request, Response, RequestBuilder> action, Request request, ActionListener<Response> listener) { client.execute(action, request, listener); }
Example #17
Source File: AbstractClient.java From crate with Apache License 2.0 | 4 votes |
@Override public <Request extends TransportRequest, Response extends TransportResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> ActionFuture<Response> execute( Action<Request, Response, RequestBuilder> action, Request request) { return client.execute(action, request); }
Example #18
Source File: AbstractClient.java From crate with Apache License 2.0 | 4 votes |
@Override public <Request extends TransportRequest, Response extends TransportResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void execute( Action<Request, Response, RequestBuilder> action, Request request, ActionListener<Response> listener) { client.execute(action, request, listener); }
Example #19
Source File: AbstractClient.java From crate with Apache License 2.0 | 4 votes |
@Override public <Request extends TransportRequest, Response extends TransportResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> ActionFuture<Response> execute( Action<Request, Response, RequestBuilder> action, Request request) { return client.execute(action, request); }
Example #20
Source File: AbstractClient.java From crate with Apache License 2.0 | 4 votes |
/** * This is the single execution point of *all* clients. */ @Override public final <Request extends TransportRequest, Response extends TransportResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void execute( Action<Request, Response, RequestBuilder> action, Request request, ActionListener<Response> listener) { doExecute(action, request, listener); }
Example #21
Source File: ElasticsearchAssertions.java From crate with Apache License 2.0 | 4 votes |
/** * Run the request from a given builder and check that it throws an exception of the right type, with a given {@link RestStatus} */ public static <E extends Throwable> void assertThrows(ActionRequestBuilder<?, ?, ?> builder, Class<E> exceptionClass, RestStatus status) { assertThrows(builder.execute(), exceptionClass, status); }
Example #22
Source File: ElasticsearchAssertions.java From crate with Apache License 2.0 | 4 votes |
public static <E extends Throwable> void assertThrows(ActionRequestBuilder<?, ?, ?> builder, RestStatus status) { assertThrows(builder.execute(), status); }
Example #23
Source File: ElasticsearchAssertions.java From crate with Apache License 2.0 | 4 votes |
public static <E extends Throwable> void assertThrows(ActionRequestBuilder<?, ?, ?> builder, RestStatus status, String extraInfo) { assertThrows(builder.execute(), status, extraInfo); }
Example #24
Source File: TransportClient.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override protected <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void doExecute(Action<Request, Response, RequestBuilder> action, Request request, ActionListener<Response> listener) { proxy.execute(action, request, listener); }
Example #25
Source File: ClientWithStats.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> ActionFuture<Response> execute( Action<Request, Response, RequestBuilder> action, Request request) { return wrapped.execute(action, request); }
Example #26
Source File: ClientWithStats.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void execute( Action<Request, Response, RequestBuilder> action, Request request, ActionListener<Response> listener) { wrapped.execute(action, request, listener); }
Example #27
Source File: ClientWithStats.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> RequestBuilder prepareExecute( Action<Request, Response, RequestBuilder> action) { return wrapped.prepareExecute(action); }
Example #28
Source File: Elasticsearch.java From sfs with Apache License 2.0 | 4 votes |
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> Observable<Optional<Response>> execute(VertxContext<Server> vertxContext, final RequestBuilder actionRequestBuilder, long timeoutMs) { return execute(vertxContext.vertx(), actionRequestBuilder, timeoutMs); }
Example #29
Source File: Jsonify.java From sfs with Apache License 2.0 | 4 votes |
public static String toString(ActionRequestBuilder builder) { return builder.request().toString(); }
Example #30
Source File: SqlElasticDeleteByQueryRequestBuilder.java From elasticsearch-sql with Apache License 2.0 | 4 votes |
@Override public ActionRequestBuilder getBuilder() { return deleteByQueryRequestBuilder; }