# Bulk IndexRequest Fails

**URL:** <https://discuss.elastic.co/t/bulk-indexrequest-fails/288074>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [October 31, 2021, 2:08am UTC](https://discuss.elastic.co/t/bulk-indexrequest-fails/288074 "2021-10-31T02:08:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![madhurir](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@madhurir](https://discuss.elastic.co/u/madhurir)\
**Post date:** [October 31, 2021, 2:08am UTC](https://discuss.elastic.co/t/bulk-indexrequest-fails/288074/1 "2021-10-31T02:08:54Z")

</div>

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

```auto
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);

```

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [October 31, 2021, 2:19am UTC](https://discuss.elastic.co/t/bulk-indexrequest-fails/288074/2 "2021-10-31T02:19:45Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-bulk.html#java-rest-high-document-bulk-request)

```auto
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"));

```

---

<div class="post-metadata">

**Author:** ![madhurir](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@madhurir](https://discuss.elastic.co/u/madhurir)\
**Post date:** [October 31, 2021, 6:29am UTC](https://discuss.elastic.co/t/bulk-indexrequest-fails/288074/3 "2021-10-31T06:29:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 31, 2021, 7:29am UTC](https://discuss.elastic.co/t/bulk-indexrequest-fails/288074/4 "2021-10-31T07:29:40Z")

</div>

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

> <https://github.com/dadoonet/injector/blob/main/src/main/java/fr/pilato/elasticsearch/injector/injector/ElasticsearchInjector.java>

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 28, 2021, 7:30am UTC](https://discuss.elastic.co/t/bulk-indexrequest-fails/288074/5 "2021-11-28T07:30:00Z")

</div>

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