Bulk IndexRequest Fails

I am using version 7.15 and trying to create bulk index request in my dev environment. Though the single indexing works, bulk indexing doesn't. I don't see any exception but I see the following in my IntelliJ logs
[ pool-11-thread-1] RestClient WARN request [POST http://localhost:9200/_bulk?timeout=1m] returned 2 warnings:

and the page following the link in the above logs shows
{"error":"Incorrect HTTP method for uri [/_bulk?timeout=1m] and method [GET], allowed: [POST, PUT]","status":405}

Here is my code

RestHighLevelClient restHighLevelClient = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", "9200", "http")));
            BulkRequest request = new BulkRequest();
            request.add(new IndexRequest("posts", "doc", "1").source(XContentType.JSON,"field", "foo"));
            request.add(new IndexRequest("posts", "doc", "2").source(XContentType.JSON,"field", "bar"));
            request.add(new IndexRequest("posts", "doc", "3").source(XContentType.JSON,"field", "baz"));
            BulkResponse bulkResponse = restHighLevelClient.bulk(request, RequestOptions.DEFAULT);

Hi @madhurir Welcome to the community.

I am not an expert on the Java HLRC but looks like your syntax perhaps is not correct? See here

BulkRequest request = new BulkRequest(); 
request.add(new IndexRequest("posts").id("1")  
        .source(XContentType.JSON,"field", "foo"));
request.add(new IndexRequest("posts").id("2")  
        .source(XContentType.JSON,"field", "bar"));
request.add(new IndexRequest("posts").id("3")  
        .source(XContentType.JSON,"field", "baz"));

No, luck. I think I need to change the http method to post/put as in the above example, it think of the requests as http get.

Welcome!

What exact version of the client are you using?

I'm using bulk with 7.15.1 with no problem on my side. Have a look at

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