• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java BulkableAction类的典型用法和代码示例

java 1次浏览

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

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

示例1: createBatchBuilder

点赞 3

import io.searchbox.action.BulkableAction; //导入依赖的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

示例2: convertToJestAction

点赞 3

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
protected BulkableAction<DocumentResult> convertToJestAction(ActionRequest req) {
  BulkableAction<DocumentResult> action;
  switch (req.key.getAction()) {
    case INDEX:
      action = getIndexAction(req);
      break;
    case UPDATE:
      action = getUpdateAction(req);
      break;
    case DELETE:
      action = getDeleteAction(req);
      break;
    default:
      throw new IllegalStateException("Unknown action: " + req.key.getAction());
  }
  return action;
}
 

开发者ID:quantiply,
项目名称:rico,
代码行数:18,
代码来源:HTTPBulkLoader.java

示例3: getAction

点赞 3

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
protected BulkableAction<DocumentResult> getAction(ActionRequest req,
                                                 Consumer<String> id,
                                                 Consumer<String> index,
                                                 Consumer<String> type,
                                                 BiConsumer<String,Object> setParameter,
                                                 Supplier<BulkableAction<DocumentResult>> build) {
  id.accept(req.key.getId().toString());
  index.accept(req.index);
  type.accept(req.docType);
  if (req.key.getVersionType() != null) {
    setParameter.accept(Parameters.VERSION_TYPE, req.key.getVersionType().toString().toLowerCase());
  }
  if (req.key.getVersion() != null) {
    setParameter.accept(Parameters.VERSION, req.key.getVersion());
  }
  return build.get();
}
 

开发者ID:quantiply,
项目名称:rico,
代码行数:18,
代码来源:HTTPBulkLoader.java

示例4: testConvertToJestActionIndex

点赞 3

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
@Test
public void testConvertToJestActionIndex() throws Exception {
  HTTPBulkLoader loader = getBulkLoader();
  ActionRequestKey key = ActionRequestKey.newBuilder()
      .setAction(Action.INDEX)
      .setId("myId")
      .build();
  BulkableAction<DocumentResult> action = loader.convertToJestAction(new HTTPBulkLoader.ActionRequest(key, "fakeindex", "faketype", 100L, "{}"));
  assertEquals("index", action.getBulkMethodName());
  assertEquals("myId", action.getId());
  assertEquals("fakeindex", action.getIndex());
  assertEquals("faketype", action.getType());
  assertEquals("{}", action.getData(new Gson()));
  assertEquals(0, action.getParameter(Parameters.VERSION).size());
  assertEquals(0, action.getParameter(Parameters.VERSION_TYPE).size());

  ActionRequestKey keyWithVersion = ActionRequestKey.newBuilder()
      .setAction(Action.INDEX)
      .setId("myId")
      .setVersion(123L)
      .setVersionType(VersionType.EXTERNAL)
      .build();
  BulkableAction<DocumentResult> actionWithVersion = loader.convertToJestAction(new HTTPBulkLoader.ActionRequest(keyWithVersion, "fakeindex", "faketype", 100L, "{}"));
  assertEquals("external", actionWithVersion.getParameter(Parameters.VERSION_TYPE).toArray()[0]);
  assertEquals(123L, actionWithVersion.getParameter(Parameters.VERSION).toArray()[0]);
}
 

开发者ID:quantiply,
项目名称:rico,
代码行数:27,
代码来源:HTTPBulkLoaderTest.java

示例5: testConvertToJestActionUpdate

点赞 3

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
@Test
public void testConvertToJestActionUpdate() throws Exception {
  HTTPBulkLoader loader = getBulkLoader();
  ActionRequestKey key = ActionRequestKey.newBuilder()
      .setAction(Action.UPDATE)
      .setId("myId")
      .setVersion(123L)
      .setVersionType(VersionType.EXTERNAL)
      .build();
  BulkableAction<DocumentResult> action = loader.convertToJestAction(new HTTPBulkLoader.ActionRequest(key, "fakeindex", "faketype", 100L, "{}"));
  assertEquals("update", action.getBulkMethodName());
  assertEquals("myId", action.getId());
  assertEquals("fakeindex", action.getIndex());
  assertEquals("faketype", action.getType());
  assertEquals("external", action.getParameter(Parameters.VERSION_TYPE).toArray()[0]);
  assertEquals(123L, action.getParameter(Parameters.VERSION).toArray()[0]);
  assertEquals("{}", action.getData(new Gson()));
}
 

开发者ID:quantiply,
项目名称:rico,
代码行数:19,
代码来源:HTTPBulkLoaderTest.java

示例6: testConvertToJestActionDelete

点赞 3

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
@Test
public void testConvertToJestActionDelete() throws Exception {
  HTTPBulkLoader loader = getBulkLoader();
  ActionRequestKey key = ActionRequestKey.newBuilder()
      .setAction(Action.DELETE)
      .setId("myId")
      .setVersion(123L)
      .setVersionType(VersionType.EXTERNAL)
      .build();
  BulkableAction<DocumentResult> action = loader.convertToJestAction(new HTTPBulkLoader.ActionRequest(key, "fakeindex", "faketype", 100L, null));
  assertEquals("delete", action.getBulkMethodName());
  assertEquals("myId", action.getId());
  assertEquals("fakeindex", action.getIndex());
  assertEquals("faketype", action.getType());
  assertEquals("external", action.getParameter(Parameters.VERSION_TYPE).toArray()[0]);
  assertEquals(123L, action.getParameter(Parameters.VERSION).toArray()[0]);
  assertEquals(null, action.getData(new Gson()));
}
 

开发者ID:quantiply,
项目名称:rico,
代码行数:19,
代码来源:HTTPBulkLoaderTest.java

示例7: index

点赞 2

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
private <E extends Element> boolean index(Set<? extends DocumentSchema<E>> schemas, E element, boolean create) {
    for (DocumentSchema<E> schema : schemas) {
        BulkableAction<DocumentResult> action = schema.addElement(element, create);
        if (action != null) {
            logger.debug("indexing element with schema: {}, element: {}, index: {}, client: {}", schema, element, action, client);
            client.bulk(element, action);
            return true;
        }
    }
    return false;
}
 

开发者ID:unipop-graph,
项目名称:unipop,
代码行数:12,
代码来源:DocumentController.java

示例8: addElement

点赞 2

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
@Override
public BulkableAction<DocumentResult> addElement(E element, boolean create) {
    Document document = toDocument(element);
    if (document == null) return null;
    Index.Builder builder = new Index.Builder(document.getFields())
            .index(document.getIndex())
            .type(document.getType())
            .id(document.getId());
    return builder.build();
}
 

开发者ID:unipop-graph,
项目名称:unipop,
代码行数:11,
代码来源:AbstractDocSchema.java

示例9: addElement

点赞 2

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
@Override
public BulkableAction<DocumentResult> addElement(Edge edge, boolean create) {
    //TODO: use the 'create' parameter to differentiate between add and update
    Vertex parentVertex = parentDirection.equals(Direction.OUT) ? edge.outVertex() : edge.inVertex();
    Document parentDoc = parentVertexSchema.toDocument(parentVertex);
    if (parentDoc == null) return null;
    Map<String, Object> edgeFields = getFields(edge);
    Map<String, Object> childFields = getVertexFields(edge, parentDirection.opposite());
    Map<String, Object> nestedFields = ConversionUtils.merge(Lists.newArrayList(edgeFields, childFields), this::mergeFields, false);
    if (nestedFields == null) return null;
    Set<String> idField = propertySchemas.stream()
            .map(schema -> schema.toFields(Collections.singleton(T.id.getAccessor()))).findFirst().get();
    try {
        HashMap<String, Object> params = new HashMap<>();
        params.put("nestedDoc", nestedFields);
        params.put("path", path);
        params.put("edgeId", edge.id());
        params.put("idField", idField.iterator().next());
        HashMap<String, Object> docMap = new HashMap<>();
        HashMap<String, Object> script = new HashMap<>();
        script.put("params", params);
        script.put("inline", UPDATE_SCRIPT);
        script.put("lang", "groovy");
        docMap.put("scripted_upsert", true);
        docMap.put("script", script);
        String json = mapper.writeValueAsString(docMap);
        return new Update.Builder(json).index(parentDoc.getIndex()).type(parentDoc.getType()).id(parentDoc.getId()).build();
    } catch (JsonProcessingException e) {
        e.printStackTrace();
        return null;
    }
}
 

开发者ID:unipop-graph,
项目名称:unipop,
代码行数:33,
代码来源:NestedEdgeSchema.java

示例10: createIndexDocuments

点赞 2

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
@Override
public void createIndexDocuments(String indexName, String documentType, Map<String, String> documentMap)
{
    LOGGER.info("Creating Elasticsearch index documents, indexName={}, documentType={}", indexName, documentType);

    List<String> allIndices = getAliases(indexName);

    allIndices.forEach((index) -> {
    // Prepare a bulk request builder
    //final BulkRequestBuilder bulkRequestBuilder = new BulkRequestBuilder(new ElasticsearchClientImpl(), BulkAction.INSTANCE);
    Bulk.Builder bulkBuilder = new Bulk.Builder();
    // For each document prepare an insert request and add it to the bulk request builder
    documentMap.forEach((id, jsonString) ->
    {
        BulkableAction createIndex = new Index.Builder(jsonString).index(index).type(documentType).id(id).build();
        bulkBuilder.addAction(createIndex);

    });

    JestResult jestResult = jestClientHelper.executeAction(bulkBuilder.build());

    // If there are failures log them
    if (!jestResult.isSucceeded())
    {
        LOGGER.error("Bulk response error = {}", jestResult.getErrorMessage());
    }
    });
}
 

开发者ID:FINRAOS,
项目名称:herd,
代码行数:29,
代码来源:IndexFunctionsDaoImpl.java

示例11: deleteIndexDocuments

点赞 2

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
/**
 * The delete index documents function will delete a list of document in the index by a list of document ids.
 */
@Override
public final void deleteIndexDocuments(String indexName, String documentType, List<Integer> ids)
{
    LOGGER.info("Deleting Elasticsearch documents from index, indexName={}, documentType={}, ids={}.", indexName, documentType,
        ids.stream().map(Object::toString).collect(Collectors.joining(",")));

    List<String> allIndices = getAliases(indexName);

    allIndices.forEach((index) -> {
    // Prepare a bulk request builder
    Bulk.Builder bulkBuilder = new Bulk.Builder();


    // For each document prepare a delete request and add it to the bulk request builder
    ids.forEach(id ->
    {
        BulkableAction action = new Delete.Builder(id.toString()).index(index).type(documentType).build();
        bulkBuilder.addAction(action);
    });

    JestResult jestResult = jestClientHelper.executeAction(bulkBuilder.build());
    // If there are failures log them
    if (!jestResult.isSucceeded())
    {
        LOGGER.error("Bulk response error = {}", jestResult.getErrorMessage());
    }
    });

}
 

开发者ID:FINRAOS,
项目名称:herd,
代码行数:33,
代码来源:IndexFunctionsDaoImpl.java

示例12: updateIndexDocuments

点赞 2

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
/**
 * The update index documents function will take as arguments the index name, document type, and a map of documents to update. The document map key is the
 * document id, and the value is the document as a JSON string.
 */
@Override
public final void updateIndexDocuments(String indexName, String documentType, Map<String, String> documentMap)
{
    LOGGER.info("Updating Elasticsearch index documents, indexName={}, documentType={}.", indexName, documentType);

    List<String> allIndices = getAliases(indexName);

    allIndices.forEach((index) -> {
        // Prepare a bulk request builder
        Bulk.Builder bulkBuilder = new Bulk.Builder();
        // For each document prepare an update request and add it to the bulk request builder
        documentMap.forEach((id, jsonString) -> {
            BulkableAction updateIndex = new Index.Builder(jsonString).index(index).type(documentType).id(id).build();
            bulkBuilder.addAction(updateIndex);
        });

        // Execute the bulk update request
        JestResult jestResult = jestClientHelper.executeAction(bulkBuilder.build());

        // If there are failures log them
        if (!jestResult.isSucceeded())
        {
            LOGGER.error("Bulk response error = {}", jestResult.getErrorMessage());
        }
    });
}
 

开发者ID:FINRAOS,
项目名称:herd,
代码行数:31,
代码来源:IndexFunctionsDaoImpl.java

示例13: addAction

点赞 2

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
/**
   * Converts request to JEST API and passes it to writer thread
   *
   * May block if internal buffer is full
   *
   * Error contract: will throw an Exception if a fatal errors occur in the writer thread
   */
  public void addAction(String source, ActionRequest req) throws Throwable {
//    if (logger.isTraceEnabled()) {
//      logger.trace(String.format("Add action: key %s, index %s/%s, doc %s", req.key, req.index, req.docType, req.document));
//    }
    BulkableAction<DocumentResult> action = convertToJestAction(req);
    WriterCommand addCmd = WriterCommand.getAddCmd(new SourcedActionRequest(source, req, action));
    sendCmd(addCmd);
  }
 

开发者ID:quantiply,
项目名称:rico,
代码行数:16,
代码来源:HTTPBulkLoader.java

示例14: toBulkableAction

点赞 2

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
public BulkableAction toBulkableAction() {
  // If payload is null, the record was a tombstone and we should delete from the index.
  return payload != null ? toIndexRequest() : toDeleteRequest();
}
 

开发者ID:confluentinc,
项目名称:kafka-connect-elasticsearch,
代码行数:5,
代码来源:IndexableRecord.java

示例15: bulk

点赞 2

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
public void bulk(Element element, BulkableAction action) {
    if(bulk != null && bulk.size() >= 500) refresh();
    if(bulk == null) bulk = new HashMap<>();
    DocumentIdentifier documentIdentifier = new DocumentIdentifier(element, action.getId(), action.getType(), action.getIndex());
    bulk.put(documentIdentifier, action);
}
 

开发者ID:unipop-graph,
项目名称:unipop,
代码行数:7,
代码来源:ElasticClient.java

示例16: addElement

点赞 2

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
@Override
public BulkableAction<DocumentResult> addElement(Vertex element, boolean create) {
    return null;
}
 

开发者ID:unipop-graph,
项目名称:unipop,
代码行数:5,
代码来源:NestedVertexSchema.java

示例17: SourcedActionRequest

点赞 2

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
public SourcedActionRequest(String source, ActionRequest request, BulkableAction<DocumentResult> action) {
  this.request = request;
  this.source = source;
  this.action = action;
}
 

开发者ID:quantiply,
项目名称:rico,
代码行数:6,
代码来源:HTTPBulkLoader.java

示例18: getIndexAction

点赞 2

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
protected BulkableAction<DocumentResult> getIndexAction(ActionRequest req) {
  Index.Builder b = new Index.Builder(req.document);
  return getAction(req, b::id, b::index, b::type, b::setParameter, b::build);
}
 

开发者ID:quantiply,
项目名称:rico,
代码行数:5,
代码来源:HTTPBulkLoader.java

示例19: getUpdateAction

点赞 2

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
protected BulkableAction<DocumentResult> getUpdateAction(ActionRequest req) {
  Update.Builder b = new Update.Builder(req.document);
  return getAction(req, b::id, b::index, b::type, b::setParameter, b::build);
}
 

开发者ID:quantiply,
项目名称:rico,
代码行数:5,
代码来源:HTTPBulkLoader.java

示例20: getDeleteAction

点赞 2

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
protected BulkableAction<DocumentResult> getDeleteAction(ActionRequest req) {
  Delete.Builder b = new Delete.Builder(req.document);
  return getAction(req, b::id, b::index, b::type, b::setParameter, b::build);
}
 

开发者ID:quantiply,
项目名称:rico,
代码行数:5,
代码来源:HTTPBulkLoader.java

示例21: addElement

点赞 1

import io.searchbox.action.BulkableAction; //导入依赖的package包/类
BulkableAction<DocumentResult> addElement(E element, boolean create); 

开发者ID:unipop-graph,
项目名称:unipop,
代码行数:2,
代码来源:DocumentSchema.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)