# How to index a document using Java REST client POST method

**URL:** <https://discuss.elastic.co/t/how-to-index-a-document-using-java-rest-client-post-method/137762>\
**Category:** Elasticsearch\
**Created:** [June 28, 2018, 8:10am UTC](https://discuss.elastic.co/t/how-to-index-a-document-using-java-rest-client-post-method/137762 "2018-06-28T08:10:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![suyash](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@suyash](https://discuss.elastic.co/u/suyash)\
**Post date:** [June 28, 2018, 8:10am UTC](https://discuss.elastic.co/t/how-to-index-a-document-using-java-rest-client-post-method/137762/1 "2018-06-28T08:10:45Z")

</div>

Hi,

I want to index a document into amazonES . I am using Java REST client .  
As per the documentation I found links to indexing a document as PUT method.

```
Map<String, String> params = Collections.emptyMap();
String jsonString = "{" +
            "\"user\":\"kimchy\"," +
            "\"postDate\":\"2013-01-30\"," +
            "\"message\":\"trying out Elasticsearch\"" +
        "}";
HttpEntity entity = new NStringEntity(jsonString, ContentType.APPLICATION_JSON);
Response response = restClient.performRequest("PUT", "/posts/doc/1", params, entity); 

```

But I would like to know how to perform POST where I don't want to provide the id .

Please assist me with any docs or links.

Thanks.

---

<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:** [June 28, 2018, 12:53pm UTC](https://discuss.elastic.co/t/how-to-index-a-document-using-java-rest-client-post-method/137762/2 "2018-06-28T12:53:44Z")

</div>

Would that work?

```
Response response = restClient.performRequest("POST", "/posts/doc", params, entity);
```

---

<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:** [July 26, 2018, 12:53pm UTC](https://discuss.elastic.co/t/how-to-index-a-document-using-java-rest-client-post-method/137762/3 "2018-07-26T12:53:51Z")

</div>

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