本文整理汇总了Java中org.elasticsearch.action.ActionRequestBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ActionRequestBuilder类的具体用法?Java ActionRequestBuilder怎么用?Java ActionRequestBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ActionRequestBuilder类属于org.elasticsearch.action包,在下文中一共展示了ActionRequestBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertBlocked
import org.elasticsearch.action.ActionRequestBuilder; //导入依赖的package包/类
/**
* 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));
}
}
}
示例2: checkUpdateAction
import org.elasticsearch.action.ActionRequestBuilder; //导入依赖的package包/类
void checkUpdateAction(boolean autoCreateIndex, TimeValue timeout, ActionRequestBuilder<?, ?, ?> builder) {
// we clean the metadata when loosing a master, therefore all operations on indices will auto create it, if allowed
long now = System.currentTimeMillis();
try {
builder.get();
fail("expected ClusterBlockException or MasterNotDiscoveredException");
} catch (ClusterBlockException | MasterNotDiscoveredException e) {
if (e instanceof MasterNotDiscoveredException) {
assertTrue(autoCreateIndex);
} else {
assertFalse(autoCreateIndex);
}
// verify we waited before giving up...
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
assertThat(System.currentTimeMillis() - now, greaterThan(timeout.millis() - 50));
}
}
示例3: checkWriteAction
import org.elasticsearch.action.ActionRequestBuilder; //导入依赖的package包/类
void checkWriteAction(boolean indexShouldBeAutoCreated, TimeValue timeout, ActionRequestBuilder<?, ?, ?> builder) {
long now = System.currentTimeMillis();
try {
builder.get();
fail("Expected ClusterBlockException");
} catch (ClusterBlockException e) {
if (indexShouldBeAutoCreated) {
// timeout is 200
assertThat(System.currentTimeMillis() - now, greaterThan(timeout.millis() - 50));
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
} else {
// timeout is 5000
assertThat(System.currentTimeMillis() - now, lessThan(timeout.millis() + 300));
}
}
}
示例4: handleRequest
import org.elasticsearch.action.ActionRequestBuilder; //导入依赖的package包/类
@Override
protected void handleRequest(RestRequest request, RestChannel channel, final Client client) throws Exception {
String sql = request.param("sql");
if (sql == null) {
sql = request.content().toUtf8();
}
SearchDao searchDao = new SearchDao(client);
ActionRequestBuilder actionRequestBuilder = searchDao.explain(sql);
ActionRequest actionRequest = actionRequestBuilder.request();
// TODO add unittests to explain. (rest level?)
if (request.path().endsWith("/_explain")) {
String jsonExplanation = ExplainManager.explain(actionRequestBuilder);
BytesRestResponse bytesRestResponse = new BytesRestResponse(RestStatus.OK, jsonExplanation);
channel.sendResponse(bytesRestResponse);
} else {
new ActionRequestExecuter(actionRequest, channel, client).execute();
}
}
示例5: explain
import org.elasticsearch.action.ActionRequestBuilder; //导入依赖的package包/类
public static String explain(ActionRequestBuilder actionRequest) throws IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, SQLFeatureNotSupportedException {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint();
if (actionRequest instanceof SearchRequestBuilder) {
((SearchRequestBuilder) actionRequest).internalBuilder().toXContent(builder, ToXContent.EMPTY_PARAMS);
} else if (actionRequest instanceof DeleteByQueryRequestBuilder) {
// access private method to get the explain...
DeleteByQueryRequestBuilder deleteRequest = ((DeleteByQueryRequestBuilder) actionRequest);
Method method = deleteRequest.getClass().getDeclaredMethod("sourceBuilder");
method.setAccessible(true);
QuerySourceBuilder sourceBuilder = (QuerySourceBuilder) method.invoke(deleteRequest);
sourceBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
} else {
throw new SQLFeatureNotSupportedException(String.format("Failed to explain class %s", actionRequest.getClass().getName()));
}
return builder.string();
}
示例6: runQuery
import org.elasticsearch.action.ActionRequestBuilder; //导入依赖的package包/类
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;
}
示例7: deleteSeries
import org.elasticsearch.action.ActionRequestBuilder; //导入依赖的package包/类
@Override
public AsyncFuture<DeleteSeries> deleteSeries(final DeleteSeries.Request request) {
final DateRange range = request.getRange();
final FindSeriesIds.Request findIds =
new FindSeriesIds.Request(request.getFilter(), range, request.getLimit());
return doto(c -> findSeriesIds(findIds).lazyTransform(ids -> {
final List<Callable<AsyncFuture<Void>>> deletes = new ArrayList<>();
for (final String id : ids.getIds()) {
deletes.add(() -> {
final List<DeleteRequestBuilder> requests = c.delete(TYPE_METADATA, id);
return async.collectAndDiscard(requests
.stream()
.map(ActionRequestBuilder::execute)
.map(this::bind)
.collect(Collectors.toList()));
});
}
return async.eventuallyCollect(deletes, newDeleteCollector(), deleteParallelism);
}));
}
示例8: FlushObject
import org.elasticsearch.action.ActionRequestBuilder; //导入依赖的package包/类
FlushObject(
String elementId,
ActionRequestBuilder actionRequestBuilder,
Future future,
int retryCount,
long retryTime
) {
this.elementId = elementId;
this.actionRequestBuilder = actionRequestBuilder;
this.future = future;
this.retryCount = retryCount;
this.retryTime = retryTime;
}
示例9: doExecute
import org.elasticsearch.action.ActionRequestBuilder; //导入依赖的package包/类
@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) {
listener.onResponse(null);
}
示例10: doExecute
import org.elasticsearch.action.ActionRequestBuilder; //导入依赖的package包/类
@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) {
request.setParentTask(parentTask);
super.doExecute(action, request, listener);
}
示例11: execute
import org.elasticsearch.action.ActionRequestBuilder; //导入依赖的package包/类
@Override
public final <Request extends ActionRequest, Response extends ActionResponse, 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;
}
示例12: filterWithHeader
import org.elasticsearch.action.ActionRequestBuilder; //导入依赖的package包/类
@Override
public Client filterWithHeader(Map<String, String> headers) {
return new FilterClient(this) {
@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) {
ThreadContext threadContext = threadPool().getThreadContext();
try (ThreadContext.StoredContext ctx = threadContext.stashAndMergeHeaders(headers)) {
super.doExecute(action, request, listener);
}
}
};
}
示例13: doExecute
import org.elasticsearch.action.ActionRequestBuilder; //导入依赖的package包/类
@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) {
// Discard the task because the Client interface doesn't use it.
executeLocally(action, request, listener);
}
示例14: testSetsParentId
import org.elasticsearch.action.ActionRequestBuilder; //导入依赖的package包/类
public void testSetsParentId() {
TaskId[] parentTaskId = new TaskId[] {new TaskId(randomAsciiOfLength(3), randomLong())};
// This mock will do nothing but verify that parentTaskId is set on all requests sent to it.
NoOpClient mock = new NoOpClient(getTestName()) {
@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) {
assertEquals(parentTaskId[0], request.getParentTask());
super.doExecute(action, request, listener);
}
};
try (ParentTaskAssigningClient client = new ParentTaskAssigningClient(mock, parentTaskId[0])) {
// All of these should have the parentTaskId set
client.bulk(new BulkRequest());
client.search(new SearchRequest());
client.clearScroll(new ClearScrollRequest());
// Now lets verify that unwrapped calls don't have the parentTaskId set
parentTaskId[0] = TaskId.EMPTY_TASK_ID;
client.unwrap().bulk(new BulkRequest());
client.unwrap().search(new SearchRequest());
client.unwrap().clearScroll(new ClearScrollRequest());
}
}
示例15: doExecute
import org.elasticsearch.action.ActionRequestBuilder; //导入依赖的package包/类
@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) {
Tracer.SpanBuilder spanBuilder = tracer.buildSpan(request.getClass().getSimpleName())
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
Span span = spanBuilder.start();
SpanDecorator.onRequest(span);
ActionListener<Response> actionFuture = new TracingResponseListener<>(listener, span);
super.doExecute(action, request, actionFuture);
}
开发者ID:opentracing-contrib,项目名称:java-elasticsearch-client,代码行数:14,代码来源:TracingPreBuiltTransportClient.java