当前位置: 首页>>代码示例>>Java>>正文


Java BulkRequest.add方法代码示例

本文整理汇总了Java中org.elasticsearch.action.bulk.BulkRequest.add方法的典型用法代码示例。如果您正苦于以下问题:Java BulkRequest.add方法的具体用法?Java BulkRequest.add怎么用?Java BulkRequest.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.action.bulk.BulkRequest的用法示例。


在下文中一共展示了BulkRequest.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepareRequest

import org.elasticsearch.action.bulk.BulkRequest; //导入方法依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    BulkRequest bulkRequest = Requests.bulkRequest();
    String defaultIndex = request.param("index");
    String defaultType = request.param("type");
    String defaultRouting = request.param("routing");
    String fieldsParam = request.param("fields");
    String defaultPipeline = request.param("pipeline");
    String[] defaultFields = fieldsParam != null ? Strings.commaDelimitedListToStringArray(fieldsParam) : null;

    String waitForActiveShards = request.param("wait_for_active_shards");
    if (waitForActiveShards != null) {
        bulkRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
    }
    bulkRequest.timeout(request.paramAsTime("timeout", BulkShardRequest.DEFAULT_TIMEOUT));
    bulkRequest.setRefreshPolicy(request.param("refresh"));
    bulkRequest.add(request.content(), defaultIndex, defaultType, defaultRouting, defaultFields, null, defaultPipeline, null, true,
        request.getXContentType());

    // short circuit the call to the transport layer
    return channel -> {
        BulkRestBuilderListener listener = new BulkRestBuilderListener(channel, request);
        listener.onResponse(bulkRequest);
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:RestNoopBulkAction.java

示例2: prepareRequest

import org.elasticsearch.action.bulk.BulkRequest; //导入方法依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    BulkRequest bulkRequest = Requests.bulkRequest();
    String defaultIndex = request.param("index");
    String defaultType = request.param("type");
    String defaultRouting = request.param("routing");
    FetchSourceContext defaultFetchSourceContext = FetchSourceContext.parseFromRestRequest(request);
    String fieldsParam = request.param("fields");
    if (fieldsParam != null) {
        DEPRECATION_LOGGER.deprecated("Deprecated field [fields] used, expected [_source] instead");
    }
    String[] defaultFields = fieldsParam != null ? Strings.commaDelimitedListToStringArray(fieldsParam) : null;
    String defaultPipeline = request.param("pipeline");
    String waitForActiveShards = request.param("wait_for_active_shards");
    if (waitForActiveShards != null) {
        bulkRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
    }
    bulkRequest.timeout(request.paramAsTime("timeout", BulkShardRequest.DEFAULT_TIMEOUT));
    bulkRequest.setRefreshPolicy(request.param("refresh"));
    bulkRequest.add(request.content(), defaultIndex, defaultType, defaultRouting, defaultFields,
        defaultFetchSourceContext, defaultPipeline, null, allowExplicitIndex, request.getXContentType());

    return channel -> client.bulk(bulkRequest, new RestStatusToXContentListener<>(channel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:RestBulkAction.java

示例3: testBulkRequestExecution

import org.elasticsearch.action.bulk.BulkRequest; //导入方法依赖的package包/类
public void testBulkRequestExecution() throws Exception {
    BulkRequest bulkRequest = new BulkRequest();
    String pipelineId = "_id";

    int numRequest = scaledRandomIntBetween(8, 64);
    for (int i = 0; i < numRequest; i++) {
        IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").setPipeline(pipelineId);
        indexRequest.source(Requests.INDEX_CONTENT_TYPE, "field1", "value1");
        bulkRequest.add(indexRequest);
    }

    when(store.get(pipelineId)).thenReturn(new Pipeline(pipelineId, null, version, new CompoundProcessor()));

    @SuppressWarnings("unchecked")
    BiConsumer<IndexRequest, Exception> requestItemErrorHandler = mock(BiConsumer.class);
    @SuppressWarnings("unchecked")
    Consumer<Exception> completionHandler = mock(Consumer.class);
    executionService.executeBulkRequest(bulkRequest.requests(), requestItemErrorHandler, completionHandler);

    verify(requestItemErrorHandler, never()).accept(any(), any());
    verify(completionHandler, times(1)).accept(null);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:PipelineExecutionServiceTests.java

示例4: testDynamicDisabled

import org.elasticsearch.action.bulk.BulkRequest; //导入方法依赖的package包/类
public void testDynamicDisabled() {
    IndexRequest request = new IndexRequest("index", "type", "1");
    request.source(Requests.INDEX_CONTENT_TYPE, "foo", 3);
    BulkRequest bulkRequest = new BulkRequest();
    bulkRequest.add(request);
    final AtomicBoolean onFailureCalled = new AtomicBoolean();

    transportBulkAction.execute(bulkRequest, new ActionListener<BulkResponse>() {
        @Override
        public void onResponse(BulkResponse bulkResponse) {
            fail("onResponse shouldn't be called");
        }

        @Override
        public void onFailure(Exception e) {
            onFailureCalled.set(true);
            assertThat(e, instanceOf(IndexNotFoundException.class));
            assertEquals("no such index and [index.mapper.dynamic] is [false]", e.getMessage());
        }
    });

    assertTrue(onFailureCalled.get());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:DynamicMappingDisabledTests.java

示例5: bulkDelete

import org.elasticsearch.action.bulk.BulkRequest; //导入方法依赖的package包/类
public String bulkDelete(String index,String type,String... ids){
	try {
		if(xclient==null){
			init();
		}
		BulkRequest request = new BulkRequest();
		for (String id : ids) {
			request.add(new DeleteRequest(index, type, id));
		}
		BulkResponse result = xclient.bulk(request);
		return result.toString();
	}catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:dev-share,项目名称:css-elasticsearch,代码行数:18,代码来源:ElasticsearchHighRestFactory.java

示例6: purgeShards

import org.elasticsearch.action.bulk.BulkRequest; //导入方法依赖的package包/类
private void purgeShards(List<IndexShard> shardsToPurge) {
    for (IndexShard shardToPurge : shardsToPurge) {
        Query query = shardToPurge.indexService().mapperService().smartNameFieldType(TTLFieldMapper.NAME).rangeQuery(null, System.currentTimeMillis(), false, true);
        Engine.Searcher searcher = shardToPurge.acquireSearcher("indices_ttl");
        try {
            logger.debug("[{}][{}] purging shard", shardToPurge.routingEntry().index(), shardToPurge.routingEntry().id());
            ExpiredDocsCollector expiredDocsCollector = new ExpiredDocsCollector();
            searcher.searcher().search(query, expiredDocsCollector);
            List<DocToPurge> docsToPurge = expiredDocsCollector.getDocsToPurge();

            BulkRequest bulkRequest = new BulkRequest();
            for (DocToPurge docToPurge : docsToPurge) {

                bulkRequest.add(new DeleteRequest().index(shardToPurge.routingEntry().index()).type(docToPurge.type).id(docToPurge.id).version(docToPurge.version).routing(docToPurge.routing));
                bulkRequest = processBulkIfNeeded(bulkRequest, false);
            }
            processBulkIfNeeded(bulkRequest, true);
        } catch (Exception e) {
            logger.warn("failed to purge", e);
        } finally {
            searcher.close();
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:IndicesTTLService.java

示例7: bulkIndexRequestBody

import org.elasticsearch.action.bulk.BulkRequest; //导入方法依赖的package包/类
@Test
public void bulkIndexRequestBody() throws Exception {
    String prefix = createPrefix();

    // given
    BulkRequest request = new BulkRequest();
    request.add(new IndexRequest(prefix + "foo", prefix + "bar", prefix + "baz")
            .source("{\"" + prefix + "content\": \"" + prefix + "hello\"}"));

    // when
    @SuppressWarnings("unchecked")
    List<String> indexedDocumentIds = template.requestBody("direct:bulk_index", request, List.class);

    // then
    assertThat(indexedDocumentIds, notNullValue());
    assertThat(indexedDocumentIds.size(), equalTo(1));
    assertThat(indexedDocumentIds, hasItem(prefix + "baz"));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:ElasticsearchBulkTest.java

示例8: bulkRequestBody

import org.elasticsearch.action.bulk.BulkRequest; //导入方法依赖的package包/类
@Test
public void bulkRequestBody() throws Exception {
    String prefix = createPrefix();

    // given
    BulkRequest request = new BulkRequest();
    request.add(new IndexRequest(prefix + "foo", prefix + "bar", prefix + "baz")
            .source("{\"" + prefix + "content\": \"" + prefix + "hello\"}"));

    // when
    BulkResponse response = template.requestBody("direct:bulk", request, BulkResponse.class);

    // then
    assertThat(response, notNullValue());
    assertEquals(prefix + "baz", response.getItems()[0].getId());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:ElasticsearchBulkTest.java

示例9: should_execute_bulk

import org.elasticsearch.action.bulk.BulkRequest; //导入方法依赖的package包/类
@Test
public void should_execute_bulk() throws ExecutionException, InterruptedException, IOException {
    BulkRequest request = new BulkRequest();

    IndexRequest action = new IndexRequest();
    action.source(source());
    action.index("the_index");
    action.type("the_type");
    action.id("the_id");

    request.add(action);
    request.add(action);
    request.add(action);
    BulkResponse response = httpClient.bulk(request).get();

    Assertions.assertThat(response.isErrors()).isFalse();
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:18,代码来源:BulkActionHandlerTest.java

示例10: addElementToBulkRequest

import org.elasticsearch.action.bulk.BulkRequest; //导入方法依赖的package包/类
public void addElementToBulkRequest(Graph graph, BulkRequest bulkRequest, IndexInfo indexInfo, Element element, Authorizations authorizations) {
    try {
        XContentBuilder json = buildJsonContentFromElement(graph, element, authorizations);
        UpdateRequest indexRequest = new UpdateRequest(indexInfo.getIndexName(), ELEMENT_TYPE, element.getId()).doc(json);
        indexRequest.retryOnConflict(MAX_RETRIES);
        indexRequest.docAsUpsert(true);
        bulkRequest.add(indexRequest);
    } catch (IOException ex) {
        throw new MemgraphException("Could not add element to bulk request", ex);
    }
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:12,代码来源:Elasticsearch5SearchIndex.java

示例11: buildBulk

import org.elasticsearch.action.bulk.BulkRequest; //导入方法依赖的package包/类
private BulkRequest buildBulk(Iterable<? extends ScrollableHitSource.Hit> docs) {
    BulkRequest bulkRequest = new BulkRequest();
    for (ScrollableHitSource.Hit doc : docs) {
        if (accept(doc)) {
            RequestWrapper<?> request = scriptApplier.apply(copyMetadata(buildRequest(doc), doc), doc);
            if (request != null) {
                bulkRequest.add(request.self());
            }
        }
    }
    return bulkRequest;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:AbstractAsyncBulkByScrollAction.java

示例12: testExecuteBulkPipelineDoesNotExist

import org.elasticsearch.action.bulk.BulkRequest; //导入方法依赖的package包/类
public void testExecuteBulkPipelineDoesNotExist() {
    CompoundProcessor processor = mock(CompoundProcessor.class);
    when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, processor));
    BulkRequest bulkRequest = new BulkRequest();

    IndexRequest indexRequest1 = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
    bulkRequest.add(indexRequest1);
    IndexRequest indexRequest2 =
            new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("does_not_exist");
    bulkRequest.add(indexRequest2);
    @SuppressWarnings("unchecked")
    BiConsumer<IndexRequest, Exception> failureHandler = mock(BiConsumer.class);
    @SuppressWarnings("unchecked")
    Consumer<Exception> completionHandler = mock(Consumer.class);
    executionService.executeBulkRequest(bulkRequest.requests(), failureHandler, completionHandler);
    verify(failureHandler, times(1)).accept(
        argThat(new CustomTypeSafeMatcher<IndexRequest>("failure handler was not called with the expected arguments") {
            @Override
            protected boolean matchesSafely(IndexRequest item) {
                return item == indexRequest2;
            }

        }),
        argThat(new CustomTypeSafeMatcher<IllegalArgumentException>("failure handler was not called with the expected arguments") {
            @Override
            protected boolean matchesSafely(IllegalArgumentException iae) {
                return "pipeline with id [does_not_exist] does not exist".equals(iae.getMessage());
            }
        })
    );
    verify(completionHandler, times(1)).accept(null);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:33,代码来源:PipelineExecutionServiceTests.java

示例13: bulkRetryTestCase

import org.elasticsearch.action.bulk.BulkRequest; //导入方法依赖的package包/类
/**
 * Execute a bulk retry test case. The total number of failures is random and the number of retries attempted is set to
 * testRequest.getMaxRetries and controled by the failWithRejection parameter.
 */
private void bulkRetryTestCase(boolean failWithRejection) throws Exception {
    int totalFailures = randomIntBetween(1, testRequest.getMaxRetries());
    int size = randomIntBetween(1, 100);
    testRequest.setMaxRetries(totalFailures - (failWithRejection ? 1 : 0));

    client.bulksToReject = client.bulksAttempts.get() + totalFailures;
    /*
     * When we get a successful bulk response we usually start the next scroll request but lets just intercept that so we don't have to
     * deal with it. We just wait for it to happen.
     */
    CountDownLatch successLatch = new CountDownLatch(1);
    DummyAsyncBulkByScrollAction action = new DummyActionWithoutBackoff() {
        @Override
        void startNextScroll(TimeValue lastBatchStartTime, int lastBatchSize) {
            successLatch.countDown();
        }
    };
    BulkRequest request = new BulkRequest();
    for (int i = 0; i < size + 1; i++) {
        request.add(new IndexRequest("index", "type", "id" + i));
    }
    action.sendBulkRequest(timeValueNanos(System.nanoTime()), request);
    if (failWithRejection) {
        BulkByScrollResponse response = listener.get();
        assertThat(response.getBulkFailures(), hasSize(1));
        assertEquals(response.getBulkFailures().get(0).getStatus(), RestStatus.TOO_MANY_REQUESTS);
        assertThat(response.getSearchFailures(), empty());
        assertNull(response.getReasonCancelled());
    } else {
        assertTrue(successLatch.await(10, TimeUnit.SECONDS));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:AsyncBulkByScrollActionTests.java

示例14: bulkUpsert

import org.elasticsearch.action.bulk.BulkRequest; //导入方法依赖的package包/类
public String bulkUpsert(String index,String type,List<Object> jsons){
		try {
			if(xclient==null){
				init();
			}
			BulkRequest request = new BulkRequest();
			for (Object json : jsons) {
				JSONObject obj = JSON.parseObject(JSON.toJSONString(json));
				String id = UUIDs.base64UUID();
				if(obj.containsKey("id")){
					id = obj.getString("id");
					obj.remove("id");
				}
//				if(obj.containsKey("id")){
//					request.add(new UpdateRequest(index, type, id).doc(obj.toJSONString(),XContentType.JSON));
//				}else{
//					request.add(new IndexRequest(index, type).source(obj.toJSONString(),XContentType.JSON));
//				}
				request.add(new UpdateRequest(index, type, id).upsert(obj.toJSONString(),XContentType.JSON));
			}
			BulkResponse result = xclient.bulk(request);
			return result.toString();
		}catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
 
开发者ID:dev-share,项目名称:css-elasticsearch,代码行数:29,代码来源:ElasticsearchHighRestFactory.java

示例15: toBulkRequest

import org.elasticsearch.action.bulk.BulkRequest; //导入方法依赖的package包/类
@Converter
public static BulkRequest toBulkRequest(List<Object> documents,
                                        Exchange exchange) {
    BulkRequest request = new BulkRequest();
    for (Object document : documents) {
        request.add(createIndexRequest(document, exchange));
    }
    return request;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:ElasticsearchActionRequestConverter.java


注:本文中的org.elasticsearch.action.bulk.BulkRequest.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。