Elasticsearch bulk indexing the documents using Java API Client

0

I have inserted some documents into my index using ElasticsearchRepository's saveAll() method and Bulk Indexing method. When I tried fetching records using elasticSearchOperations and I see the fields name has changed in the documents which are bulk indexed. Example - the actual field name was "userName" and in the bulk indexed documents the field name was changed into "user_name". I also noticed that in hits().source(), the "_class" is missing in bulk indexed records. Can anyone help me what I did wrong?

My BulkRequest builder looks like this

 final BulkResponse response = client.bulk(builder -> {
            for (Product product : products) {
                builder.index(index)
                       .operations(ob -> {
                           if (product.getId() != null) {
                               ob.index(ib -> ib.document(product).id(product.getId()));
                           } else {
                               ob.index(ib -> ib.document(product));
                           }
                           return ob;
                       });
            }
            return builder;
        });

I'm not able to figure out what went wrong.

It seems that your ElasticsearchRepository is converting camelCase names ("userName") to snake_case ("user_name") when inserting documents in Elasticsearch.

You should look a the configuration of your ElasticsearchRepository.