Bulk insert in elasticsearch datastream using elasticsearch-java 8.6.2

I'm trying to bulk insert documents in datastream in elasticsearch using java with (ElasticsearchClient) (elasticsearch-java) 8.6.2.

I checked documentation of elasticsearch-java and found information around bulk indexing in index, and i'm able to insert bulk data in index. Bulk: indexing multiple documents | Elasticsearch Java API Client [8.7] | Elastic

List<Product> products = fetchProducts();

BulkRequest.Builder br = new BulkRequest.Builder();

for (Product product : products) {
    br.operations(op -> op           
        .index(idx -> idx            
            .index("products")       
            .id(product.getSku())
            .document(product)
        )
    );
}

BulkResponse result = esClient.bulk(br.build());

// Log errors, if any
if (result.errors()) {
    logger.error("Bulk had errors");
    for (BulkResponseItem item: result.items()) {
        if (item.error() != null) {
            logger.error(item.error().reason());
        }
    }
}

I'm trying to bulk insert documents in datastream in elasticsearch using java with (ElasticsearchClient) (elasticsearch-java) 8.6.2.

I checked official documentation of elasticsearch-java and found information around bulk indexing in index, and i'm able to insert bulk data in index. Bulk: indexing multiple documents | Elasticsearch Java API Client [8.7] | Elastic

List<Product> products = fetchProducts();

BulkRequest.Builder br = new BulkRequest.Builder();

for (Product product : products) {
    br.operations(op -> op           
        .index(idx -> idx            
            .index("products")       
            .id(product.getSku())
            .document(product)
        )
    );
}

BulkResponse result = esClient.bulk(br.build());

// Log errors, if any
if (result.errors()) {
    logger.error("Bulk had errors");
    for (BulkResponseItem item: result.items()) {
        if (item.error() != null) {
            logger.error(item.error().reason());
        }
    }
}

But when I'm trying to insert data in datastream using this code i'm getting below error: only write ops with an op type of create are allowed in data-streams

class Product
{
   String name;
   Map<String, Object> info;
}

How can we bulk insert data from java object (Product.info) in batches of 1000 in data streams?

Thanks in advance.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.