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


Java Bulk类代码示例

本文整理汇总了Java中io.searchbox.core.Bulk的典型用法代码示例。如果您正苦于以下问题:Java Bulk类的具体用法?Java Bulk怎么用?Java Bulk使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: configReturnsACopyOfServerUrisList

import io.searchbox.core.Bulk; //导入依赖的package包/类
@Test
public void configReturnsACopyOfServerUrisList() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    builder.withServerUris("http://localhost:9200;http://localhost:9201;http://localhost:9202");
    ClientObjectFactory<JestClient, Bulk> config = builder.build();

    // when
    Collection<String> serverUrisList = config.getServerList();
    serverUrisList.add("test");

    // then
    assertNotEquals(serverUrisList.size(), config.getServerList().size());

}
 
开发者ID:rfoltyns,项目名称:log4j2-elasticsearch,代码行数:17,代码来源:JestHttpObjectFactoryTest.java

示例2: createBatchListener

import io.searchbox.core.Bulk; //导入依赖的package包/类
@Override
public Function<Bulk, Boolean> createBatchListener(FailoverPolicy failoverPolicy) {
    return new Function<Bulk, Boolean>() {

        private Function<Bulk, Boolean> failureHandler = createFailureHandler(failoverPolicy);
        private JestClient client = createClient();

        @Override
        public Boolean apply(Bulk bulk) {
            JestResultHandler<JestResult> jestResultHandler = createResultHandler(bulk, failureHandler);
            client.executeAsync(bulk, jestResultHandler);
            return true;
        }

    };
}
 
开发者ID:rfoltyns,项目名称:log4j2-elasticsearch,代码行数:17,代码来源:JestHttpObjectFactory.java

示例3: createBatchBuilder

import io.searchbox.core.Bulk; //导入依赖的package包/类
@Override
public BatchBuilder<Bulk> createBatchBuilder() {
    return new BatchBuilder<Bulk>() {

        private final Bulk.Builder builder = new Bulk.Builder();

        @Override
        public void add(Object item) {
            builder.addAction((BulkableAction)item);
        }

        @Override
        public Bulk build() {
            return builder.build();
        }
    };
}
 
开发者ID:rfoltyns,项目名称:log4j2-elasticsearch,代码行数:18,代码来源:JestBulkOperations.java

示例4: failureHandlerExecutesFailoverForEachBatchItemSeparately

import io.searchbox.core.Bulk; //导入依赖的package包/类
@Test
public void failureHandlerExecutesFailoverForEachBatchItemSeparately() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    ClientObjectFactory<JestClient, Bulk> config = builder.build();

    FailoverPolicy failoverPolicy = Mockito.spy(new NoopFailoverPolicy());

    String payload1 = "test1";
    String payload2 = "test2";
    Bulk bulk = new Bulk.Builder()
            .addAction(spy(new Index.Builder(payload1)).build())
            .addAction(spy(new Index.Builder(payload2)).build())
            .build();

    // when
    config.createFailureHandler(failoverPolicy).apply(bulk);

    // then
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(failoverPolicy, times(2)).deliver((String) captor.capture());

    assertTrue(captor.getAllValues().contains(payload1));
    assertTrue(captor.getAllValues().contains(payload2));
}
 
开发者ID:rfoltyns,项目名称:log4j2-elasticsearch,代码行数:27,代码来源:JestHttpObjectFactoryTest.java

示例5: clientIsCalledWhenListenerIsNotified

import io.searchbox.core.Bulk; //导入依赖的package包/类
@Test
public void clientIsCalledWhenListenerIsNotified() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    ClientObjectFactory<JestClient, Bulk> config = spy(builder.build());

    JestClient mockedJestClient = mock(JestClient.class);
    when(config.createClient()).thenReturn(mockedJestClient);

    FailoverPolicy failoverPolicy = spy(new NoopFailoverPolicy());
    Function<Bulk, Boolean> listener = config.createBatchListener(failoverPolicy);

    String payload1 = "test1";
    String payload2 = "test2";
    Bulk bulk = createTestBatch(payload1, payload2);

    // when
    listener.apply(bulk);

    // then
    ArgumentCaptor<Bulk> captor = ArgumentCaptor.forClass(Bulk.class);
    verify(mockedJestClient, times(1)).executeAsync((Bulk) captor.capture(), Mockito.any());

    assertEquals(bulk, captor.getValue());
}
 
开发者ID:rfoltyns,项目名称:log4j2-elasticsearch,代码行数:27,代码来源:JestHttpObjectFactoryTest.java

示例6: failoverIsExecutedAfterNonSuccessfulRequest

import io.searchbox.core.Bulk; //导入依赖的package包/类
@Test
public void failoverIsExecutedAfterNonSuccessfulRequest() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    JestHttpObjectFactory config = spy(builder.build());

    String payload1 = "test1";
    String payload2 = "test2";
    Bulk bulk = createTestBatch(payload1, payload2);

    Function<Bulk, Boolean> failoverHandler = mock(Function.class);
    JestResultHandler<JestResult> resultHandler = config.createResultHandler(bulk, failoverHandler);

    JestResult result = mock(JestResult.class);
    when(result.isSucceeded()).thenReturn(false);

    // when
    resultHandler.completed(result);

    // then
    ArgumentCaptor<Bulk> captor = ArgumentCaptor.forClass(Bulk.class);
    verify(failoverHandler, times(1)).apply(captor.capture());

    assertEquals(bulk, captor.getValue());
}
 
开发者ID:rfoltyns,项目名称:log4j2-elasticsearch,代码行数:27,代码来源:JestHttpObjectFactoryTest.java

示例7: failoverIsNotExecutedAfterSuccessfulRequest

import io.searchbox.core.Bulk; //导入依赖的package包/类
@Test
public void failoverIsNotExecutedAfterSuccessfulRequest() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    JestHttpObjectFactory config = spy(builder.build());

    String payload1 = "test1";
    String payload2 = "test2";
    Bulk bulk = createTestBatch(payload1, payload2);

    Function<Bulk, Boolean> failoverHandler = mock(Function.class);
    JestResultHandler<JestResult> resultHandler = config.createResultHandler(bulk, failoverHandler);

    JestResult result = mock(JestResult.class);
    when(result.isSucceeded()).thenReturn(true);

    // when
    resultHandler.completed(result);

    // then
    verify(failoverHandler, never()).apply(Mockito.any(Bulk.class));
}
 
开发者ID:rfoltyns,项目名称:log4j2-elasticsearch,代码行数:24,代码来源:JestHttpObjectFactoryTest.java

示例8: failoverIsExecutedAfterFailedRequest

import io.searchbox.core.Bulk; //导入依赖的package包/类
@Test
public void failoverIsExecutedAfterFailedRequest() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    JestHttpObjectFactory config = spy(builder.build());

    String payload1 = "test1";
    String payload2 = "test2";
    Bulk bulk = createTestBatch(payload1, payload2);

    Function<Bulk, Boolean> failoverHandler = mock(Function.class);
    JestResultHandler<JestResult> resultHandler = config.createResultHandler(bulk, failoverHandler);

    // when
    resultHandler.failed(new IOException());

    // then
    ArgumentCaptor<Bulk> captor = ArgumentCaptor.forClass(Bulk.class);
    verify(failoverHandler, times(1)).apply(captor.capture());

    assertEquals(bulk, captor.getValue());
}
 
开发者ID:rfoltyns,项目名称:log4j2-elasticsearch,代码行数:24,代码来源:JestHttpObjectFactoryTest.java

示例9: executeQueueItemActions

import io.searchbox.core.Bulk; //导入依赖的package包/类
/**
 * Execute locked items from the MongoDB Queue Repository.
 * 
 * @param lockedItems A list of locked queues items.
 */
private void executeQueueItemActions(List<ElasticsearchUpdateQueueItem> lockedItems) {
  Bulk.Builder bulkBuilder = new Bulk.Builder();
  for (ElasticsearchUpdateQueueItem lockedItem : lockedItems) {
    switch (lockedItem.getAction()) {
      case DELETE:
        addDeleteActions(lockedItem, bulkBuilder);
        break;
      case UPSERT:
        addUpsertActions(lockedItem, bulkBuilder);
        break;
      default:
        throw new NotImplementedException("Processing queue item with action "
            + lockedItem.getAction() + " has not been implemented!");
    }
  }

  // execute the bulk update/delete
  elasticsearchDao.executeBulk(bulkBuilder.build());

  // finally delete the queue items
  queueItemRepository.delete(lockedItems);
}
 
开发者ID:dzhw,项目名称:metadatamanagement,代码行数:28,代码来源:ElasticsearchUpdateQueueService.java

示例10: replace

import io.searchbox.core.Bulk; //导入依赖的package包/类
@Override
public void replace(InternalGroup group) throws IOException {
  Bulk bulk =
      new Bulk.Builder()
          .defaultIndex(indexName)
          .defaultType(GROUPS)
          .addAction(insert(GROUPS, group))
          .refresh(true)
          .build();
  JestResult result = client.execute(bulk);
  if (!result.isSucceeded()) {
    throw new IOException(
        String.format(
            "Failed to replace group %s in index %s: %s",
            group.getGroupUUID().get(), indexName, result.getErrorMessage()));
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:ElasticGroupIndex.java

示例11: replace

import io.searchbox.core.Bulk; //导入依赖的package包/类
@Override
public void replace(AccountState as) throws IOException {
  Bulk bulk =
      new Bulk.Builder()
          .defaultIndex(indexName)
          .defaultType(ACCOUNTS)
          .addAction(insert(ACCOUNTS, as))
          .refresh(true)
          .build();
  JestResult result = client.execute(bulk);
  if (!result.isSucceeded()) {
    throw new IOException(
        String.format(
            "Failed to replace account %s in index %s: %s",
            as.getAccount().getId(), indexName, result.getErrorMessage()));
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:ElasticAccountIndex.java

示例12: replace

import io.searchbox.core.Bulk; //导入依赖的package包/类
@Override
public void replace(ProjectData projectState) throws IOException {
  Bulk bulk =
      new Bulk.Builder()
          .defaultIndex(indexName)
          .defaultType(PROJECTS)
          .addAction(insert(PROJECTS, projectState))
          .refresh(true)
          .build();
  JestResult result = client.execute(bulk);
  if (!result.isSucceeded()) {
    throw new IOException(
        String.format(
            "Failed to replace project %s in index %s: %s",
            projectState.getProject().getName(), indexName, result.getErrorMessage()));
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:ElasticProjectIndex.java

示例13: deleteDocuments

import io.searchbox.core.Bulk; //导入依赖的package包/类
@Override
public <T extends Document> void deleteDocuments(Collection<T> documents) throws Exception {
    final Builder bulkBuilder = new Bulk.Builder();
    bulkBuilder.defaultIndex(Constants.INDEX);
    
    for (Document d : documents){
        bulkBuilder.addAction(new Delete.Builder(d.getUUID().toString())
        .index(Constants.INDEX)
        .type(d.getType().toString()).build());
    }
    
    runESOperation(new ESOperation<Void>() {

        @Override
        public Void run() throws Exception {
            conn.execute(bulkBuilder.build());
            return null;
        }
    });
}
 
开发者ID:TravelTracker,项目名称:TravelTracker,代码行数:21,代码来源:ElasticSearchHelper.java

示例14: saveDocuments

import io.searchbox.core.Bulk; //导入依赖的package包/类
@Override
public <T extends Document> void saveDocuments(Collection<T> documents) throws Exception {
    final Builder bulkBuilder = new Bulk.Builder();
    for (Document d : documents){
        bulkBuilder.addAction(new Index.Builder(d)
        .index(Constants.INDEX)
        .type(d.getType().toString())
        .id(d.getUUID().toString()).build());
    }
    
    runESOperation(new ESOperation<Void>() {

        @Override
        public Void run() throws Exception {
            conn.execute(bulkBuilder.build());
            return null;
        }
    });
    
}
 
开发者ID:TravelTracker,项目名称:TravelTracker,代码行数:21,代码来源:ElasticSearchHelper.java

示例15: builderIndex_Bulk

import io.searchbox.core.Bulk; //导入依赖的package包/类
public void builderIndex_Bulk(List<Entity> entityList, boolean cleanBeforeInsert) {
  int nRecords = entityList.size();
  long start = System.currentTimeMillis();
  try {
    if (cleanBeforeInsert) {
      jestHttpClient.execute(new DeleteIndex(new DeleteIndex.Builder(_esIndexName)));
    }
    JestResult jestResult = jestHttpClient.execute(new IndicesExists.Builder(_esIndexName).build());
    if (!jestResult.isSucceeded()) {
      jestHttpClient.execute(new CreateIndex.Builder(_esIndexName).build());
    }


    SerializeBeans2JSON sb2json = new SerializeBeans2JSON(); 
    Bulk.Builder bulkBuilder = new Bulk.Builder();
    for (int i = 0; i < nRecords; i++) {
      Index index = new Index
          .Builder(sb2json.serializeBeans2JSON(entityList.get(i)))
      .index(_esIndexName)
      .type(_esTypeName)
      .id(entityList.get(i).getEntityID())
      .build();
      bulkBuilder.addAction(index);
    }
    jestHttpClient.execute(bulkBuilder.build());
  } catch (Exception e) {
    e.printStackTrace();
  }
  long end = System.currentTimeMillis();
  LOG.info("->> Bulk: total time for create index --> " + (end - start) + " milliseconds, # of records: " + nRecords); 
}
 
开发者ID:faustineinsun,项目名称:WiseCrowdRec,代码行数:32,代码来源:JestElasticsearchManipulator.java


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