In REST, POST is typically used to create a resource while PUT and PATCH are used to replace the entire resource or partially update the resource. Why then, is POST used for a partial update of a resource? Even the Wikipedia artical in this commonly referenced discussion conflicts with the Elasticsearch REST API. Granted, I have only started working in Elasticsearch, but my progress is being hindered by having to relearn what HTTP methods I need to use for REST operations that only apply to one service.
One solution would be to add a server config to enable an updated REST interface in an upcoming version. Then in a later version change it so that the updated REST API is enabled by default, then remove the old API all together in the following version. That won't break backward compatibility and give developers and vendors time to update libraries and applications. I know that is a pain from a developer standpoint, being a developer myself, but I (and I assume others) would appreciate everything being standardized so we don't have to remember multiple ways of using HTTP methods for REST.
The simple answer is that Elasticsearch tries to be RESTful, but isn't dogmatic. It chooses the verbs that make the most sense for the API, not necessarily to follow RESTful conventions to a tee. Trying to be too dogmatic leads to very strange APIs.
The Update API is a bit tricky. It can provide a complete replacement of the original document, partial update, or scripted update which may or may not have an effect. The Update API is thus sometimes idempotent, and sometimes not (e.g. incrementing a counter).
Using PUT is not really appropriate because the operation may not be idempotent. An Update may also fail if the document doesn't exist, which is at odds with using PUT (where'd you expect it to create the document if it doesn't exist, since you are PUTing the resource)
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.