本文整理汇总了Java中org.elasticsearch.action.ActionRequest类的典型用法代码示例。如果您正苦于以下问题:Java ActionRequest类的具体用法?Java ActionRequest怎么用?Java ActionRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ActionRequest类属于org.elasticsearch.action包,在下文中一共展示了ActionRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: performRequestAsync
import org.elasticsearch.action.ActionRequest; //导入依赖的package包/类
<Req extends ActionRequest, Resp> void performRequestAsync(Req request,
CheckedFunction<Req, Request, IOException> requestConverter,
CheckedFunction<Response, Resp, IOException> responseConverter,
ActionListener<Resp> listener, Set<Integer> ignores, Header... headers) {
ActionRequestValidationException validationException = request.validate();
if (validationException != null) {
listener.onFailure(validationException);
return;
}
Request req;
try {
req = requestConverter.apply(request);
} catch (Exception e) {
listener.onFailure(e);
return;
}
ResponseListener responseListener = wrapResponseListener(responseConverter, listener, ignores);
client.performRequestAsync(req.method, req.endpoint, req.params, req.entity, responseListener, headers);
}
示例2: setResponseFailureIfIndexMatches
import org.elasticsearch.action.ActionRequest; //导入依赖的package包/类
private boolean setResponseFailureIfIndexMatches(AtomicArray<BulkItemResponse> responses, int idx, ActionRequest request, String index, Throwable e) {
if (request instanceof IndexRequest) {
IndexRequest indexRequest = (IndexRequest) request;
if (index.equals(indexRequest.index())) {
responses.set(idx, new BulkItemResponse(idx, "index", new BulkItemResponse.Failure(indexRequest.index(), indexRequest.type(), indexRequest.id(), e)));
return true;
}
} else if (request instanceof DeleteRequest) {
DeleteRequest deleteRequest = (DeleteRequest) request;
if (index.equals(deleteRequest.index())) {
responses.set(idx, new BulkItemResponse(idx, "delete", new BulkItemResponse.Failure(deleteRequest.index(), deleteRequest.type(), deleteRequest.id(), e)));
return true;
}
} else if (request instanceof UpdateRequest) {
UpdateRequest updateRequest = (UpdateRequest) request;
if (index.equals(updateRequest.index())) {
responses.set(idx, new BulkItemResponse(idx, "update", new BulkItemResponse.Failure(updateRequest.index(), updateRequest.type(), updateRequest.id(), e)));
return true;
}
} else {
throw new ElasticsearchException("Parsed unknown request in bulk actions: " + request.getClass().getSimpleName());
}
return false;
}
示例3: writeOnLocal
import org.elasticsearch.action.ActionRequest; //导入依赖的package包/类
public <Request extends ActionRequest, Response extends ActionResponse> void writeOnLocal(final Request request,
final ActionListener<Response> listener) {
final ActionListener<Response> next = wrap(res -> {
final short classType = RequestUtils.getClassType(request);
if (classType > 0) {
synchronized (this) {
streamOutput.writeShort(classType);
request.writeTo(streamOutput);
if (flushPerDoc) {
streamOutput.flush();
}
}
} else {
throw new ElasticsearchException("Unknown request: " + request);
}
listener.onResponse(res);
}, listener::onFailure);
if (streamOutput == null || streamOutput.getByteCount() > dataFileSize) {
createStreamOutput(next);
} else {
next.onResponse(null);
}
}
示例4: getClassType
import org.elasticsearch.action.ActionRequest; //导入依赖的package包/类
public static <Request extends ActionRequest> short getClassType(final Request request) {
if (DeleteRequest.class.isInstance(request)) {
return RequestUtils.TYPE_DELETE;
} else if (DeleteByQueryRequest.class.isInstance(request)) {
return RequestUtils.TYPE_DELETE_BY_QUERY;
} else if (IndexRequest.class.isInstance(request)) {
return RequestUtils.TYPE_INDEX;
} else if (UpdateRequest.class.isInstance(request)) {
return RequestUtils.TYPE_UPDATE;
} else if (UpdateByQueryRequest.class.isInstance(request)) {
return RequestUtils.TYPE_UPDATE_BY_QUERY;
} else if (BulkRequest.class.isInstance(request)) {
return RequestUtils.TYPE_BULK;
}
return 0;
}
示例5: newRequest
import org.elasticsearch.action.ActionRequest; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <Request extends ActionRequest> Request newRequest(final short classType) {
switch (classType) {
case RequestUtils.TYPE_DELETE:
return (Request) new DeleteRequest();
case RequestUtils.TYPE_DELETE_BY_QUERY:
return (Request) new DeleteByQueryRequest();
case RequestUtils.TYPE_INDEX:
return (Request) new IndexRequest();
case RequestUtils.TYPE_UPDATE:
return (Request) new UpdateRequest();
case RequestUtils.TYPE_UPDATE_BY_QUERY:
return (Request) new UpdateByQueryRequest();
case RequestUtils.TYPE_BULK:
return (Request) new BulkRequest();
default:
throw new ElasticsearchException("Unknown request type: " + classType);
}
}
示例6: apply
import org.elasticsearch.action.ActionRequest; //导入依赖的package包/类
@Override
public <Request extends ActionRequest, Response extends ActionResponse> void apply(final Task task, final String action,
final Request request, final ActionListener<Response> listener, final ActionFilterChain<Request, Response> chain) {
if (logger.isDebugEnabled()) {
logger.debug("node: " + nodeName() + ", action: " + action + ", request: " + request);
}
final Supplier<Response> executor = getExecutor(task, action, request);
if (executor != null) {
indexingProxyService.write(request, ActionListener.wrap(res -> {
listener.onResponse(executor.get());
}, listener::onFailure));
} else if (indexingProxyService.isRenewAction(action)) {
indexingProxyService.renew(ActionListener.wrap(res -> {
chain.proceed(task, action, request, listener);
}, listener::onFailure));
} else {
chain.proceed(task, action, request, listener);
}
}
示例7: GetRequest
import org.elasticsearch.action.ActionRequest; //导入依赖的package包/类
/**
* Copy constructor that creates a new get request that is a copy of the one provided as an argument.
* The new request will inherit though headers and context from the original request that caused it.
*/
public GetRequest(GetRequest getRequest, ActionRequest originalRequest) {
super(originalRequest);
this.index = getRequest.index;
this.type = getRequest.type;
this.id = getRequest.id;
this.routing = getRequest.routing;
this.preference = getRequest.preference;
this.fields = getRequest.fields;
this.fetchSourceContext = getRequest.fetchSourceContext;
this.refresh = getRequest.refresh;
this.realtime = getRequest.realtime;
this.version = getRequest.version;
this.versionType = getRequest.versionType;
this.ignoreErrorsOnGeneratedFields = getRequest.ignoreErrorsOnGeneratedFields;
}
示例8: SearchRequest
import org.elasticsearch.action.ActionRequest; //导入依赖的package包/类
/**
* Copy constructor that creates a new search request that is a copy of the one provided as an argument.
* The new request will inherit though headers and context from the original request that caused it.
*/
public SearchRequest(SearchRequest searchRequest, ActionRequest originalRequest) {
super(originalRequest);
this.searchType = searchRequest.searchType;
this.indices = searchRequest.indices;
this.routing = searchRequest.routing;
this.preference = searchRequest.preference;
this.templateSource = searchRequest.templateSource;
this.template = searchRequest.template;
this.source = searchRequest.source;
this.extraSource = searchRequest.extraSource;
this.requestCache = searchRequest.requestCache;
this.scroll = searchRequest.scroll;
this.types = searchRequest.types;
this.indicesOptions = searchRequest.indicesOptions;
}
示例9: proceed
import org.elasticsearch.action.ActionRequest; //导入依赖的package包/类
@Override @SuppressWarnings("unchecked")
public void proceed(Task task, String actionName, ActionRequest request, ActionListener listener) {
int i = index.getAndIncrement();
try {
if (i < this.action.filters.length) {
this.action.filters[i].apply(task, actionName, request, listener, this);
} else if (i == this.action.filters.length) {
this.action.doExecute(task, (Request) request, new FilteredActionListener<Response>(actionName, listener, new ResponseFilterChain(this.action.filters, logger)));
} else {
listener.onFailure(new IllegalStateException("proceed was called too many times"));
}
} catch(Throwable t) {
logger.trace("Error during transport action execution.", t);
listener.onFailure(t);
}
}
示例10: execute
import org.elasticsearch.action.ActionRequest; //导入依赖的package包/类
/**
* Execute the ActionRequest and returns the REST response using the channel.
*/
public void execute() throws Exception {
ActionRequest request = requestBuilder.request();
//todo: maby change to instanceof multi?
if(requestBuilder instanceof JoinRequestBuilder){
executeJoinRequestAndSendResponse();
}
else if (request instanceof SearchRequest) {
client.search((SearchRequest) request, new RestStatusToXContentListener<SearchResponse>(channel));
} else if (requestBuilder instanceof SqlElasticDeleteByQueryRequestBuilder) {
throw new UnsupportedOperationException("currently not support delete on elastic 2.0.0");
}
else if(request instanceof GetIndexRequest) {
this.requestBuilder.getBuilder().execute( new GetIndexRequestRestListener(channel, (GetIndexRequest) request));
}
else {
throw new Exception(String.format("Unsupported ActionRequest provided: %s", request.getClass().getName()));
}
}
示例11: writeTo
import org.elasticsearch.action.ActionRequest; //导入依赖的package包/类
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeByte(consistencyLevel.id());
out.writeVInt(requests.size());
for (ActionRequest request : requests) {
if (request instanceof IndexRequest) {
out.writeByte((byte) 0);
} else if (request instanceof DeleteRequest) {
out.writeByte((byte) 1);
} else if (request instanceof UpdateRequest) {
out.writeByte((byte) 2);
}
request.writeTo(out);
}
out.writeBoolean(refresh);
timeout.writeTo(out);
}
示例12: getActions
import org.elasticsearch.action.ActionRequest; //导入依赖的package包/类
@Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
return Arrays.asList(new ActionHandler<>(ReindexAction.INSTANCE, TransportReindexAction.class),
new ActionHandler<>(UpdateByQueryAction.INSTANCE, TransportUpdateByQueryAction.class),
new ActionHandler<>(DeleteByQueryAction.INSTANCE, TransportDeleteByQueryAction.class),
new ActionHandler<>(RethrottleAction.INSTANCE, TransportRethrottleAction.class));
}
示例13: applyScript
import org.elasticsearch.action.ActionRequest; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected <T extends ActionRequest> T applyScript(Consumer<Map<String, Object>> scriptBody) {
IndexRequest index = new IndexRequest("index", "type", "1").source(singletonMap("foo", "bar"));
ScrollableHitSource.Hit doc = new ScrollableHitSource.BasicHit("test", "type", "id", 0);
ExecutableScript executableScript = new SimpleExecutableScript(scriptBody);
when(scriptService.executable(any(CompiledScript.class), Matchers.<Map<String, Object>>any()))
.thenReturn(executableScript);
AbstractAsyncBulkByScrollAction<Request> action = action(scriptService, request().setScript(EMPTY_SCRIPT));
RequestWrapper<?> result = action.buildScriptApplier().apply(AbstractAsyncBulkByScrollAction.wrap(index), doc);
return (result != null) ? (T) result.self() : null;
}
示例14: performRequestAsyncAndParseEntity
import org.elasticsearch.action.ActionRequest; //导入依赖的package包/类
private <Req extends ActionRequest, Resp> void performRequestAsyncAndParseEntity(Req request,
CheckedFunction<Req, Request, IOException> requestConverter,
CheckedFunction<XContentParser, Resp, IOException> entityParser,
ActionListener<Resp> listener, Set<Integer> ignores, Header... headers) {
performRequestAsync(request, requestConverter, (response) -> parseEntity(response.getEntity(), entityParser),
listener, ignores, headers);
}
示例15: clientIsCalledWhenBatchItemIsAdded
import org.elasticsearch.action.ActionRequest; //导入依赖的package包/类
@Test
public void clientIsCalledWhenBatchItemIsAdded() {
// given
Builder builder = createTestObjectFactoryBuilder();
ClientObjectFactory<TransportClient, BulkRequest> config = spy(builder.build());
Settings settings = Settings.builder()
.put("node.local", true)
.build();
TransportClient client = spy(TransportClient.builder().settings(settings).build());
client.addTransportAddress(new LocalTransportAddress("1"));
when(config.createClient()).thenReturn(client);
FailoverPolicy failoverPolicy = spy(new NoopFailoverPolicy());
BulkProcessorFactory bulkProcessorFactory = new BulkProcessorFactory();
BatchEmitter batchEmitter = bulkProcessorFactory.createInstance(
1,
100,
config,
failoverPolicy);
String payload1 = "test1";
ActionRequest testRequest = createTestRequest(payload1);
// when
batchEmitter.add(testRequest);
// then
ArgumentCaptor<BulkRequest> captor = ArgumentCaptor.forClass(BulkRequest.class);
verify(client, times(1)).bulk(captor.capture(), Mockito.any());
assertEquals(payload1, new BulkRequestIntrospector().items(captor.getValue()).iterator().next());
}