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

Is there a real difference between POST and PUT in the ElasticSearch API? When I look at documentation such as this, 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?

1 Like

Take a look at http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_empty_search.html#get_vs_post

1 Like

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?

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

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

3 Likes

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?

2 Likes

That's definitely part of it, yes :slight_smile:

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 ?

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.

Read

1 Like

Thank you David.

I have another issue, after creating an index, it not showing up in -
curl -XGET "http://xxxxxx.com:9200/_cat/indices?v" ...

but I'm not sure of the exact issue, it's just shows nothing after: curl -XPOST 'xxx.xx.com:9200/_bulk?pretty' --data-binary @xxxx_xx.json ... ?

can you please help me out with this ....

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

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

1 Like