# What is the difference between POST an PUT in the ElasticSearch API?

**URL:** <https://discuss.elastic.co/t/what-is-the-difference-between-post-an-put-in-the-elasticsearch-api/31995>\
**Category:** Elasticsearch\
**Created:** [October 12, 2015, 9:21am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-post-an-put-in-the-elasticsearch-api/31995 "2015-10-12T09:21:15Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jornane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jornane/32/5193_2.png) [@jornane](https://discuss.elastic.co/u/jornane)\
**Post date:** [October 12, 2015, 9:21am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-post-an-put-in-the-elasticsearch-api/31995/1 "2015-10-12T09:21:15Z")

</div>

Is there a real difference between POST and PUT in the ElasticSearch API? When I look at documentation such as [this](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html#mappings), it looks like they can be substituted for each other.

I ask because I write an application in which, under certain circumstances, user input is supposed to be put in ElasticSearch, and I don't want users indadvertedly changing configuration by submitting specially crafted documents. I thought I could do this by always using PUT (because I assumed POST would be used for configuration changes), but it seems like I misunderstood.

What I am asking for is, how can I see the difference between putting a document into ElasticSearch and changing configuration to ElasticSearch. If it's not a distinction of HTTP method, is it a distinction of URL?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 12, 2015, 9:22am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-post-an-put-in-the-elasticsearch-api/31995/2 "2015-10-12T09:22:08Z")

</div>

Take a look at [http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/\_empty\_search.html#get\_vs\_post](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_empty_search.html#get_vs_post)

---

<div class="post-metadata">

**Author:** ![jornane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jornane/32/5193_2.png) [@jornane](https://discuss.elastic.co/u/jornane)\
**Post date:** [October 12, 2015, 9:24am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-post-an-put-in-the-elasticsearch-api/31995/3 "2015-10-12T09:24:55Z")

</div>

Thanks, this describes the difference between GET and POST quite well, but my question is about PUT vs POST. I do understand that POST can be used as a substitute for GET when it is not possible to use GET with a body, but does the same apply to PUT? Can POST be used as a substitute for PUT? If so, how does ElasticSearch know which method was actually meant to be used if POST is used?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 12, 2015, 9:26am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-post-an-put-in-the-elasticsearch-api/31995/4 "2015-10-12T09:26:58Z")

</div>

Oh, sorry! Used to people asking for that one and muscle memory kicked in 😛  
I'm not sure how we differentiate there sorry.

---

<div class="post-metadata">

**Author:** ![benfranklin79](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benfranklin79/32/3620_2.png) [@benfranklin79](https://discuss.elastic.co/u/benfranklin79)\
**Post date:** [October 12, 2015, 9:30am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-post-an-put-in-the-elasticsearch-api/31995/5 "2015-10-12T09:30:08Z")

</div>

The only difference I'm aware of is that a POST can be used to achieve auto-generation of ids whereas a PUT is used when you want to specify an id. See the following for more details:

[https://www.elastic.co/guide/en/elasticsearch/guide/current/index-doc.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/index-doc.html)

---

<div class="post-metadata">

**Author:** ![jornane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jornane/32/5193_2.png) [@jornane](https://discuss.elastic.co/u/jornane)\
**Post date:** [October 12, 2015, 9:37am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-post-an-put-in-the-elasticsearch-api/31995/6 "2015-10-12T09:37:25Z")

</div>

> [@benfranklin79](#):
>
> [Indexing a Document | Elasticsearch: The Definitive Guide [2.x] | Elastic](https://www.elastic.co/guide/en/elasticsearch/guide/current/index-doc.html)

The information there makes sense to me, but it leaves a few stones unturned:

`/{index}/{type}/{id}`  
Clear: I can use `PUT` to add a document because I specified the `id`. It is my responsibility that the `id` doesn't clash with an existing document, or it will be overwritten.  
Unclear: Would it be correct (allowed) to use `POST` here?  
Unclear: Does **EVERY** `POST` store a document? Or are there certain "special" documents that change configuration?

`/{index}/{type}`  
Clear: I MUST use `POST` to add a document, because I don't specify an `id`.  
Unclear: Can I safely add documents without fearing overwrite?  
Unclear: Does **EVERY** `POST` store a document? Or are there certain "special" documents that change configuration?

`/{index}`  
Unclear: what will a `POST` operation do here? Or a `PUT` operation? I found examples that change configuration, but are there other possibilities?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 12, 2015, 9:41am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-post-an-put-in-the-elasticsearch-api/31995/7 "2015-10-12T09:41:39Z")

</div>

That's definitely part of it, yes 🙂

---

<div class="post-metadata">

**Author:** ![kpandran](https://avatars.discourse-cdn.com/v4/letter/k/f04885/32.png) [@kpandran](https://discuss.elastic.co/u/kpandran)\
**Post date:** [January 19, 2017, 3:09am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-post-an-put-in-the-elasticsearch-api/31995/8 "2017-01-19T03:09:07Z")

</div>

Hi all,

It seems this ques kept unnoticed ..

I have tried POST and PUT in both the scenarios but I haven't figured out the differences.

Only diff I observed is, uuid created for the PUT is different from what I expected still not sure of the functional diff.

I also gone through the Documentation from the ES, it says: PUT- stores docs at url and POST-stores under url in elasticsearch

Does anyone know the diff b/w at and under this scenario ?

---

<div class="post-metadata">

**Author:** ![Ravi\_Shanker\_Reddy](https://avatars.discourse-cdn.com/v4/letter/r/a5b964/32.png) [@Ravi\_Shanker\_Reddy](https://discuss.elastic.co/u/Ravi_Shanker_Reddy)\
**Post date:** [January 19, 2017, 4:31am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-post-an-put-in-the-elasticsearch-api/31995/9 "2017-01-19T04:31:56Z")

</div>

As of my knowledge the http requests have some standards. In that PUT is using to insert a new value and the POST is used for update the existing values. Its not belongs to ES alone. The POST, PUT, DELETE, GET, HEAD etc... belongs to all http requests.

Have a look here.

> <https://stackoverflow.com/questions/630453/put-vs-post-in-rest>

---

<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:** [January 19, 2017, 6:44am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-post-an-put-in-the-elasticsearch-api/31995/10 "2017-01-19T06:44:24Z")

</div>

Read

> [@When to use PUT versus POST?](https://discuss.elastic.co/t/when-to-use-put-versus-post/68550/2):
>
> It's all about REST semantics. POST basically that you are posting a request which is going to modify the server state. POST index/type { "foo": "bar" } will generate an \_id server side and will index the document with this \_id. PUT is used to send a resource to the server. PUT index/type/id { "foo": "bar" } will put or update a document named index/type/id in the server. Makes sense? More details here: [https://en.wikipedia.org/wiki/Representational\_state\_transfer](https://en.wikipedia.org/wiki/Representational_state_transfer)

---

<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:** [January 25, 2017, 7:38am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-post-an-put-in-the-elasticsearch-api/31995/12 "2017-01-25T07:38:45Z")

</div>

@kpandran Open a new thread and provide exactly what you are doing.

Read the following as an example of what you should provide:

> [@About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21):
>
> The heart of the free and open Elastic Stack Elasticsearch is a distributed, RESTful search and analytics engine capable of addressing a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data for lightning fast search, fine‑tuned relevancy, and powerful analytics that scale with ease. warning PLEASE READ THIS SECTION IF IT'S YOUR FIRST POST Some useful links: [elasticsearch reference guide](http://www.elastic.co/guide/en/elasticsearch/reference/current/index.html)[elasticsearch user guide](http://www.elastic.co/guide/en/elasticsearch/guide/current/index.html)[elasticsearch plugins](https://www.elastic.co/guide/en/elasticsearch/plugins/current/index.html)[elasticsearch cl…](https://www.elastic.co/guide/en/elasticsearch/client/index.html)

---

<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 5, 2017, 10:03pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-post-an-put-in-the-elasticsearch-api/31995/13 "2017-07-05T22:03:53Z")

</div>


