當前位置: 首頁>>代碼示例>>Java>>正文


Java ActionRequestBuilder類代碼示例

本文整理匯總了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));
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:27,代碼來源:ElasticsearchAssertions.java

示例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));
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:NoMasterNodeIT.java

示例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));
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:NoMasterNodeIT.java

示例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();
	}
}
 
開發者ID:lane-cn,項目名稱:elasticsql,代碼行數:23,代碼來源:RestSqlAction.java

示例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();
}
 
開發者ID:lane-cn,項目名稱:elasticsql,代碼行數:19,代碼來源:ExplainManager.java

示例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;
}
 
開發者ID:sirensolutions,項目名稱:siren-join,代碼行數:17,代碼來源:TermsByQueryBenchmark.java

示例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);
    }));
}
 
開發者ID:spotify,項目名稱:heroic,代碼行數:26,代碼來源:MetadataBackendKV.java

示例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;
}
 
開發者ID:mware-solutions,項目名稱:memory-graph,代碼行數:14,代碼來源:Elasticsearch5SearchIndex.java

示例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);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:8,代碼來源:NoOpClient.java

示例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);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:9,代碼來源:ParentTaskAssigningClient.java

示例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;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:8,代碼來源:AbstractClient.java

示例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);
            }
        }
    };
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:AbstractClient.java

示例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);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:9,代碼來源:NodeClient.java

示例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());
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:29,代碼來源:ParentTaskAssigningClientTests.java

示例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


注:本文中的org.elasticsearch.action.ActionRequestBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。