Java Code Examples for org.elasticsearch.action.index.IndexRequest

The following examples show how to use org.elasticsearch.action.index.IndexRequest. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: conductor   Source File: ElasticSearchRestDAOV5.java    License: Apache License 2.0 7 votes vote down vote up
private void indexObject(final String index, final String docType, final String docId, final Object doc) {

        byte[] docBytes;
        try {
            docBytes = objectMapper.writeValueAsBytes(doc);
        } catch (JsonProcessingException e) {
            logger.error("Failed to convert {} '{}' to byte string", docType, docId);
            return;
        }

        IndexRequest request = new IndexRequest(index, docType, docId);
        request.source(docBytes, XContentType.JSON);

        if(bulkRequests.get(docType) == null) {
            bulkRequests.put(docType, new BulkRequests(System.currentTimeMillis(), new BulkRequest()));
        }

        bulkRequests.get(docType).getBulkRequest().add(request);
        if (bulkRequests.get(docType).getBulkRequest().numberOfActions() >= this.indexBatchSize) {
            indexBulkRequest(docType);
        }
    }
 
Example 2
Source Project: SpringBootLearn   Source File: ElasticsearchUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * bulkProcessor 批量增加
 * @Author lihaodong
 * @Description
 * @Date 20:17 2018/12/21
 * @Param [indexName, type, bookList]
 * @return void
 **/
public static void bulkProcessorAdd(String indexName, String type, List<Book> bookList) {
    bookList.stream().parallel().forEach(
            book -> {
                try {
                    bulk.add(new IndexRequest(indexName, type, book.getId()).source(XContentFactory.jsonBuilder()
                            .startObject()
                            .field("id", book.getId())
                            .field("name", book.getName())
                            .field("creatDate", book.getCreatDate())
                            .field("price", book.getPrice())
                            .field("message", book.getMessage())
                            .endObject()));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
    );
}
 
Example 3
Source Project: anomaly-detection   Source File: CheckpointDaoTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void putModelCheckpoint_getIndexRequest() {
    checkpointDao.putModelCheckpoint(modelId, model);

    ArgumentCaptor<IndexRequest> indexRequestCaptor = ArgumentCaptor.forClass(IndexRequest.class);
    verify(clientUtil)
        .timedRequest(
            indexRequestCaptor.capture(),
            anyObject(),
            Matchers.<BiConsumer<IndexRequest, ActionListener<IndexResponse>>>anyObject()
        );
    IndexRequest indexRequest = indexRequestCaptor.getValue();
    assertEquals(indexName, indexRequest.index());
    assertEquals(CheckpointDao.DOC_TYPE, indexRequest.type());
    assertEquals(modelId, indexRequest.id());
    Set<String> expectedSourceKeys = new HashSet<String>(Arrays.asList(CheckpointDao.FIELD_MODEL, CheckpointDao.TIMESTAMP));
    assertEquals(expectedSourceKeys, indexRequest.sourceAsMap().keySet());
    assertEquals(model, indexRequest.sourceAsMap().get(CheckpointDao.FIELD_MODEL));
    assertNotNull(indexRequest.sourceAsMap().get(CheckpointDao.TIMESTAMP));
}
 
Example 4
/**
 * Prepare a Runnable to send an index request to store the element, invalidates the cache on success
 */
private void store(FeatureStoreRequest request, Task task, ActionListener<FeatureStoreResponse> listener) {

    try {
        Optional<ClearCachesNodesRequest> clearCachesNodesRequest = buildClearCache(request);
        IndexRequest indexRequest = buildIndexRequest(task, request);
        client.execute(IndexAction.INSTANCE, indexRequest, wrap(
                (r) -> {
                    // Run and forget, log only if something bad happens
                    // but don't wait for the action to be done nor set the parent task.
                    clearCachesNodesRequest.ifPresent((req) -> clearCachesAction.execute(req, wrap(
                            (r2) -> {
                            },
                            (e) -> logger.error("Failed to clear cache", e))));
                    listener.onResponse(new FeatureStoreResponse(r));
                },
                listener::onFailure));
    } catch (IOException ioe) {
        listener.onFailure(ioe);
    }
}
 
Example 5
@Test
public void testSavingAdResult() throws IOException {
    setUpSavingAnomalyResultIndex(false);
    doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        assertTrue(String.format("The size of args is %d.  Its content is %s", args.length, Arrays.toString(args)), args.length >= 2);
        IndexRequest request = invocation.getArgument(0);
        ActionListener<IndexResponse> listener = invocation.getArgument(1);
        assertTrue(request != null && listener != null);
        listener.onResponse(mock(IndexResponse.class));
        return null;
    }).when(client).index(any(IndexRequest.class), ArgumentMatchers.<ActionListener<IndexResponse>>any());
    AnomalyResultHandler handler = new AnomalyResultHandler(
        client,
        settings,
        clusterService,
        indexNameResolver,
        anomalyDetectionIndices,
        threadPool
    );
    handler.indexAnomalyResult(TestHelpers.randomAnomalyDetectResult());
    assertEquals(1, testAppender.countMessage((AnomalyResultHandler.SUCCESS_SAVING_MSG)));
}
 
Example 6
private IndexRequest prepareRequest(final TikaDocument document, final TikaDocument parent, TikaDocument root, final int level) throws IOException {
    IndexRequest req = new IndexRequest(indexName, esCfg.indexType, document.getId());
    Map<String, Object> jsonDocument = getDocumentMap(document);

    if (parent == null && isDuplicate(document.getId())) {
        IndexRequest indexRequest = new IndexRequest(indexName, esCfg.indexType, Entity.HASHER.hash(document.getPath()));
        indexRequest.source(getDuplicateMap(document));
        indexRequest.setRefreshPolicy(esCfg.refreshPolicy);
        return indexRequest;
    }

    if (parent != null) {
        jsonDocument.put(DEFAULT_PARENT_DOC_FIELD, parent.getId());
        jsonDocument.put("rootDocument", root.getId());
        req.routing(root.getId());
    }
    jsonDocument.put("extractionLevel", level);
    req = req.source(jsonDocument);
    req.setRefreshPolicy(esCfg.refreshPolicy);
    return req;
}
 
Example 7
@Override
protected void populateData(TransportClient tc) {

    tc.index(new IndexRequest("deals").type("deals").id("0").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
            .source("{\"amount\": 10}", XContentType.JSON)).actionGet();
    tc.index(new IndexRequest("deals").type("deals").id("1").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
            .source("{\"amount\": 1500}", XContentType.JSON)).actionGet();

    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("q");
    System.out.println(Strings.toString(tc.search(new SearchRequest().indices(".opendistro_security")).actionGet()));
    tc.search(new SearchRequest().indices("deals")).actionGet();
}
 
Example 8
Source Project: skywalking   Source File: ITElasticSearchClient.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void bulk() throws InterruptedException {
    BulkProcessor bulkProcessor = client.createBulkProcessor(2000, 10, 2);

    Map<String, String> source = new HashMap<>();
    source.put("column1", "value1");
    source.put("column2", "value2");

    for (int i = 0; i < 100; i++) {
        IndexRequest indexRequest = new IndexRequest("bulk_insert_test", "type", String.valueOf(i));
        indexRequest.source(source);
        bulkProcessor.add(indexRequest);
    }

    bulkProcessor.flush();
    bulkProcessor.awaitClose(2, TimeUnit.SECONDS);
}
 
Example 9
Source Project: incubator-gobblin   Source File: ElasticsearchWriterBase.java    License: Apache License 2.0 6 votes vote down vote up
protected Pair<BulkRequest, FutureCallbackHolder> prepareBatch(Batch<Object> batch, WriteCallback callback) {
  BulkRequest bulkRequest = new BulkRequest();
  final StringBuilder stringBuilder = new StringBuilder();
  for (Object record : batch.getRecords()) {
    try {
      byte[] serializedBytes = this.serializer.serializeToJson(record);
      log.debug("serialized record: {}", serializedBytes);
      IndexRequest indexRequest = new IndexRequest(this.indexName, this.indexType)
          .source(serializedBytes, 0, serializedBytes.length, XContentType.JSON);
      if (this.idMappingEnabled) {
        String id = this.typeMapper.getValue(this.idFieldName, record);
        indexRequest.id(id);
        stringBuilder.append(";").append(id);
      }
      bulkRequest.add(indexRequest);
    }
    catch (Exception e) {
      log.error("Encountered exception {}", e);
    }
  }
  FutureCallbackHolder futureCallbackHolder = new FutureCallbackHolder(callback,
      exception -> log.error("Batch: {} failed on ids; {} with exception {}", batch.getId(),
          stringBuilder.toString(), exception),
      this.malformedDocPolicy);
  return new Pair(bulkRequest, futureCallbackHolder);
}
 
Example 10
Source Project: Elasticsearch   Source File: BulkRequest.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 11
Source Project: javabase   Source File: UpdateMappingFieldDemo.java    License: Apache License 2.0 6 votes vote down vote up
private static void prepareData(IndicesAdminClient indicesAdminClient) throws InterruptedException {
    BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
    //批量添加
    for (int i = 0; i < 1000; i++) {
        ItemInfo iteminfo=new ItemInfo(i,"商品"+i, new Random().nextFloat(),new Date());
        // 当opType是Index时,如果文档id存在,更新文档,否则创建文档 当opType是Create,如果文档id存在,抛出文档存在的错误 *
        IndexRequestBuilder indexRequestBuilder = client.prepareIndex(INDEX_NAME_v1, INDEX_TYPE).setId(i+"").setSource(JSONObject.toJSONString(iteminfo)).setOpType(IndexRequest.OpType.INDEX);
        bulkRequestBuilder.add(indexRequestBuilder);
        //数据日期不一样
    }
    BulkResponse bulkResponse = bulkRequestBuilder.execute().actionGet();
    if (bulkResponse.hasFailures()) {
     log.error("bulk index error:{}",bulkResponse.buildFailureMessage());
    } else {
        log.info("index docs : {}" , bulkResponse);
    }
}
 
Example 12
@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeString(index);
    timeout.writeTo(out);
    out.writeLong(ingestId);
    shardId.writeTo(out);
    out.writeVInt(actionRequests.size());
    for (ActionRequest<?> actionRequest : actionRequests) {
        if (actionRequest == null) {
            out.writeBoolean(false);
            continue;
        }
        out.writeBoolean(true);
        if (actionRequest instanceof IndexRequest) {
            out.writeBoolean(true);
        } else if (actionRequest instanceof DeleteRequest) {
            out.writeBoolean(false);
        } else {
            throw new ElasticsearchException("action request not supported: " + actionRequest.getClass().getName());
        }
        actionRequest.writeTo(out);
    }
}
 
Example 13
Source Project: flink   Source File: Elasticsearch6SinkExample.java    License: Apache License 2.0 6 votes vote down vote up
private static IndexRequest createIndexRequest(String element, ParameterTool parameterTool) {
	Map<String, Object> json = new HashMap<>();
	json.put("data", element);

	String index;
	String type;

	if (element.startsWith("message #15")) {
		index = ":intentional invalid index:";
		type = ":intentional invalid type:";
	} else {
		index = parameterTool.getRequired("index");
		type = parameterTool.getRequired("type");
	}

	return Requests.indexRequest()
		.index(index)
		.type(type)
		.id(element)
		.source(json);
}
 
Example 14
Source Project: skywalking   Source File: RestHighLevelClientCase.java    License: Apache License 2.0 6 votes vote down vote up
private void index(RestHighLevelClient client, String indexName) throws IOException {
    XContentBuilder builder = XContentFactory.jsonBuilder();
    builder.startObject();
    {
        builder.field("author", "Marker");
        builder.field("title", "Java programing.");
    }
    builder.endObject();
    IndexRequest indexRequest = new IndexRequest(indexName, "_doc", "1").source(builder);

    IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
    if (indexResponse.status().getStatus() >= 400) {
        String message = "elasticsearch index data fail.";
        logger.error(message);
        throw new RuntimeException(message);
    }
}
 
Example 15
Source Project: storm-crawler   Source File: MetricsConsumer.java    License: Apache License 2.0 6 votes vote down vote up
private void indexDataPoint(TaskInfo taskInfo, Date timestamp, String name,
        double value) {
    try {
        XContentBuilder builder = jsonBuilder().startObject();
        builder.field("stormId", stormID);
        builder.field("srcComponentId", taskInfo.srcComponentId);
        builder.field("srcTaskId", taskInfo.srcTaskId);
        builder.field("srcWorkerHost", taskInfo.srcWorkerHost);
        builder.field("srcWorkerPort", taskInfo.srcWorkerPort);
        builder.field("name", name);
        builder.field("value", value);
        builder.field("timestamp", timestamp);
        builder.endObject();

        IndexRequest indexRequest = new IndexRequest(
                getIndexName(timestamp)).source(builder);
        connection.getProcessor().add(indexRequest);
    } catch (Exception e) {
        LOG.error("problem when building request for ES", e);
    }
}
 
Example 16
@Override
public boolean indexData(IndexMetadata indexMetadata, String data) {
  IndexRequest indexRequest = new IndexRequest(indexMetadata.getName(), TYPE);
  if (indexMetadata.getId() != null && !indexMetadata.getId().isEmpty()) {
    indexRequest.id(indexMetadata.getId());
  }
  indexRequest.source(data, XContentType.JSON);
  indexRequest.routing(indexMetadata.getRouting());

  try {
    IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
    return indexResponse.status().equals(RestStatus.CREATED) || indexResponse.status().equals(RestStatus.OK);
  } catch (IOException e) {
    log.error("Could not index '#{}' to index '{}'.", indexMetadata.getRouting(), indexMetadata.getName(), e);
  }
  return false;
}
 
Example 17
Source Project: arctic-sea   Source File: ElasticsearchDataHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public IndexResponse persist(Map<String, Object> dataMap) throws ElasticsearchGenerationException, IOException {
    if (!settings.isLoggingEnabled()) {
        return null;
    }
    if (adminHandler.getElasticsearchClient() == null) {
        throw new NullPointerException("Client is not initialized. Data will not be persisted.");
    }

    dataMap.put(ServiceEventDataMapping.TIMESTAMP_FIELD.getName(), DateTime.now(DateTimeZone.UTC));
    dataMap.put(ServiceEventDataMapping.UUID_FIELD.getName(), settings.getUuid());
    logger.debug("Persisting {}", dataMap);
    IndexResponse response = adminHandler.getElasticsearchClient().index(
            new IndexRequest(settings.getIndexId()).type(settings.getTypeId()).source(dataMap),
            RequestOptions.DEFAULT);
    return response;
}
 
Example 18
Source Project: blue-marlin   Source File: TestBase.java    License: Apache License 2.0 6 votes vote down vote up
private void putTBRDocs() throws IOException, JSONException
{
    File[] files = getFiles("docs/tbr");
    for (File file : files)
    {
        String content = readFile(file);
        JSONObject jsonObject = new JSONObject(content);
        ObjectMapper mapper = new ObjectMapper();
        Map map = mapper.readValue(content, new TypeReference<Map<String, Object>>()
        {
        });
        rhlclient.index(new IndexRequest()
                .index(properties.getProperty("es.tbr.index"))
                .type(properties.getProperty("es.tbr.type"))
                .id(jsonObject.getString("uckey")).source(map));
    }
}
 
Example 19
Source Project: bdt   Source File: ElasticSearchUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Indexes a document.
 *
 * @param indexName
 * @param id          unique identifier of the document
 * @param document
 * @throws Exception
 */
public void indexDocument(String indexName, String id, String document) {
    IndexRequest request = new IndexRequest(indexName).id(id).source(document, XContentType.JSON);
    try {
        client.index(request, RequestOptions.DEFAULT);
    } catch (IOException e) {
        throw new ElasticsearchException("Error indexing document");
    }
}
 
Example 20
Source Project: samza   Source File: DefaultIndexRequestFactoryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetIndexRequestWithPartitionKey() throws Exception {
  IndexRequest indexRequest = INDEX_REQUEST_FACTORY.getIndexRequest(
      new OutgoingMessageEnvelope(SYSTEM, "shardKey", "id", EMPTY_MSG));

  assertEquals("shardKey", indexRequest.routing());
}
 
Example 21
protected void populateData(TransportClient tc) {

        tc.index(new IndexRequest("prop1").type("_doc").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
                .source("{\"prop_replace\": \"yes\", \"amount\": 1010}", XContentType.JSON)).actionGet();
        tc.index(new IndexRequest("prop1").type("_doc").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
                .source("{\"prop_replace\": \"no\", \"amount\": 2020}", XContentType.JSON)).actionGet();
        tc.index(new IndexRequest("prop2").type("_doc").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
                .source("{\"role\": \"prole1\", \"amount\": 3030}", XContentType.JSON)).actionGet();
        tc.index(new IndexRequest("prop2").type("_doc").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
                .source("{\"role\": \"prole2\", \"amount\": 4040}", XContentType.JSON)).actionGet();
        tc.index(new IndexRequest("prop2").type("_doc").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
                .source("{\"role\": \"prole3\", \"amount\": 5050}", XContentType.JSON)).actionGet();

    }
 
Example 22
Source Project: flink   Source File: Elasticsearch2SinkExample.java    License: Apache License 2.0 5 votes vote down vote up
private static IndexRequest createIndexRequest(String element, ParameterTool parameterTool) {
	Map<String, Object> json = new HashMap<>();
	json.put("data", element);

	return Requests.indexRequest()
		.index(parameterTool.getRequired("index"))
		.type(parameterTool.getRequired("type"))
		.id(element)
		.source(json);
}
 
Example 23
Source Project: flink   Source File: ElasticsearchSinkBaseTest.java    License: Apache License 2.0 5 votes vote down vote up
/** Tests that any bulk failure in the listener callbacks is rethrown on an immediately following checkpoint. */
@Test
public void testBulkFailureRethrownOnCheckpoint() throws Throwable {
	final DummyElasticsearchSink<String> sink = new DummyElasticsearchSink<>(
		new HashMap<String, String>(), new SimpleSinkFunction<String>(), new NoOpFailureHandler());

	final OneInputStreamOperatorTestHarness<String, Object> testHarness =
		new OneInputStreamOperatorTestHarness<>(new StreamSink<>(sink));

	testHarness.open();

	// setup the next bulk request, and let the whole bulk request fail
	sink.setFailNextBulkRequestCompletely(new Exception("artificial failure for bulk request"));
	testHarness.processElement(new StreamRecord<>("msg"));
	verify(sink.getMockBulkProcessor(), times(1)).add(any(IndexRequest.class));

	// manually execute the next bulk request
	sink.manualBulkRequestWithAllPendingRequests();

	try {
		testHarness.snapshot(1L, 1000L);
	} catch (Exception e) {
		// the snapshot should have failed with the bulk request failure
		Assert.assertTrue(e.getCause().getCause().getMessage().contains("artificial failure for bulk request"));

		// test succeeded
		return;
	}

	Assert.fail();
}
 
Example 24
Source Project: alchemy   Source File: Elasticsearch6TableSink.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public IndexRequest createIndexRequest(
        String index,
        String docType,
        XContentType contentType,
        byte[] document) {
    return new IndexRequest(index, docType)
            .source(document, contentType);
}
 
Example 25
Source Project: canal   Source File: ESConnection.java    License: Apache License 2.0 5 votes vote down vote up
public ES7xIndexRequest(String index, String id){
    if (mode == ESClientMode.TRANSPORT) {
        indexRequestBuilder = transportClient.prepareIndex();
        indexRequestBuilder.setIndex(index);
        indexRequestBuilder.setId(id);
    } else {
        indexRequest = new IndexRequest(index);
        indexRequest.id(id);
    }
}
 
Example 26
protected void populateData(TransportClient tc) {

        tc.index(new IndexRequest("logstash-2016").type("logs").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
                .source("{\"message\":\"mymsg1a\", \"ipaddr\": \"10.0.0.0\",\"msgid\": \"12\"}", XContentType.JSON)).actionGet();
        tc.index(new IndexRequest("logstash-2016").type("logs").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
                .source("{\"message\":\"mymsg1b\", \"ipaddr\": \"10.0.0.1\",\"msgid\": \"14\"}", XContentType.JSON)).actionGet();
        tc.index(new IndexRequest("logstash-2018").type("logs").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
                .source("{\"message\":\"mymsg1c\", \"ipaddr\": \"10.0.0.2\",\"msgid\": \"12\"}", XContentType.JSON)).actionGet();
        tc.index(new IndexRequest("logstash-2018").type("logs").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
                .source("{\"message\":\"mymsg1d\", \"ipaddr\": \"10.0.0.3\",\"msgid\": \"14\"}", XContentType.JSON)).actionGet();
            }
 
Example 27
Source Project: blue-marlin   Source File: ESRichClientImp.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public IndexResponse index(IndexRequest indexRequest, String refreshPolicy) throws IOException
{
    indexRequest.setRefreshPolicy(refreshPolicy);
    IndexResponse indexResponse = rhlclient.index(indexRequest);
    return indexResponse;
}
 
Example 28
Source Project: blue-marlin   Source File: BookingDaoESImp.java    License: Apache License 2.0 5 votes vote down vote up
public String createBookingBucket(BookingBucket bookingBucket) throws IOException
{
    Map sourceMap = CommonUtil.convertToMap(bookingBucket);
    IndexRequest indexRequest = new IndexRequest(this.bookingBucketsIndex, ES_TYPE);
    indexRequest.source(sourceMap);
    IndexResponse indexResponse = esclient.index(indexRequest, WriteRequest.RefreshPolicy.WAIT_UNTIL.getValue());
    return indexResponse.getId();
}
 
Example 29
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    tookInMillis = in.readLong();
    ingestId = in.readLong();
    if (in.readBoolean()) {
        shardId = ShardId.readShardId(in);
    }
    successCount = in.readVInt();
    quorumShards = in.readVInt();
    actionRequests = new LinkedList<>();
    int size = in.readVInt();
    for (int i = 0; i < size; i++) {
        boolean exists = in.readBoolean();
        if (exists) {
            boolean b = in.readBoolean();
            if (b) {
                IndexRequest indexRequest = new IndexRequest();
                indexRequest.readFrom(in);
                actionRequests.add(indexRequest);
            } else {
                DeleteRequest deleteRequest = new DeleteRequest();
                deleteRequest.readFrom(in);
                actionRequests.add(deleteRequest);
            }
        } else {
            actionRequests.add(null);
        }
    }
    failures = new LinkedList<>();
    size = in.readVInt();
    for (int i = 0; i < size; i++) {
        failures.add(IngestActionFailure.from(in));
    }
}
 
Example 30
Source Project: flink   Source File: Elasticsearch5SinkExample.java    License: Apache License 2.0 5 votes vote down vote up
private static IndexRequest createIndexRequest(String element, ParameterTool parameterTool) {
	Map<String, Object> json = new HashMap<>();
	json.put("data", element);

	return Requests.indexRequest()
		.index(parameterTool.getRequired("index"))
		.type(parameterTool.getRequired("type"))
		.id(element)
		.source(json);
}