As far as I know, POST
is usually used for changing the state of the server, and PUT
usually for updating the information. If I am creating a new index, should it not be POST instead of PUT? PUT
does make sense when creating a document as it changes the state of data.

- 14,253
- 38
- 134
- 263
-
Does this answer your question? [What is the difference between POST and PUT in HTTP?](https://stackoverflow.com/questions/630453/what-is-the-difference-between-post-and-put-in-http) – Joel Apr 16 '21 at 12:56
-
@Joel umm.. OK. – Volatil3 Apr 16 '21 at 13:17
-
Yeah well... Not sure what other answer you expect. There are reasons for using PUT over POST, whiich - when you boil it down, is what you are asking for. Also, the answer in the post I linked, provides a great illustration of why to use PUT in this very scenario. Hence, it answers your question.. If you aren't satisfied with the answer. **go find it** https://github.com/elastic/elasticsearch – Joel Apr 16 '21 at 13:42
-
@Joel For docs creation, they use `POST` and for update `PUT`? – Volatil3 Apr 17 '21 at 07:55
1 Answers
Your statement
As far as I know, POST is usually used for changing the state of the server, and PUT usually for updating the information.
does conform to the conventional HTTP vs CRUD semantics:
HTTP method | CRUD equivalent | Description |
---|---|---|
POST | Create | Let the target resource process the representation enclosed in the request. |
PUT | Update | Set the target resource’s state to the state defined by the representation enclosed in the request. |
However, the PUT spec also stipulates that:
The PUT method requests that the state of the target resource be created or replaced with the state defined by the representation enclosed in the request message payload
As such, PUT can (and is) used in Elasticsearch to both create an index AND update its [settings and mappings].
Also, keep in mind that it's rarely just a matter of strict adherence to the semantics. One of the creators of ES put it this way:
It's all about REST semantics.
And our understanding of the semantics at the time when we made the APIs. And backwards compatibility constraints. And whatever "feels" natural to the person who implemented the API.
Where it makes a lot of sense Elasticsearch maps the HTTP verbs to useful things. But when it doesn't make a ton of sense we just go with whatever verb feels good rather than trying to be super strict about REST. Also, we don't do linked data, instead relying on you to build links from context. I'm told that is particularly non-REST. But it is what we do.

- 1
- 1

- 15,787
- 4
- 23
- 68