Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some APIs don't contain information from http status in the body #4416

Closed
honzakral opened this issue Dec 11, 2013 · 7 comments
Closed

Some APIs don't contain information from http status in the body #4416

honzakral opened this issue Dec 11, 2013 · 7 comments

Comments

@honzakral
Copy link
Contributor

When the information is only in the HTTP status code, which is often not communicated to the client code, it can get lost.

For index api which doesn't distinguish between a document being created and re-indexed I propose to add a created field to the resulting json:

# curl -X PUT localhost:9200/t/i/1?pretty -d '{}'
{
    "ok" : true,
    "_index" : "t",
    "_type" : "i",
    "_id" : "1",
    "_version" : 1,
    "created": true
}

# curl -X PUT localhost:9200/t/i/1?pretty -d '{}'
{
    "ok" : true,
    "_index" : "t",
    "_type" : "i",
    "_id" : "1",
    "_version" : 2,
    "created": false
}

If there are any other API endpoints that doesn't replicate the information from http status in the json body add them in this single issue.

@brusic
Copy link
Contributor

brusic commented Dec 11, 2013

Wouldn't the _version field denote whether or not a document was created or updated? Or course, this method would not work with applications that provide their own versioning mechanism.

The bulk API returns the type of action executed (IndexResponse, DeleteResponse, UpdateResponse), perhaps the API should return the action type and not simply created or not (but that might be redundant in a few settings).

@honzakral
Copy link
Contributor Author

the _version field is only telling when using automatic versioning and even then I wouldn't feel comfortable forcing people to check for version number in order to determine something like that - seems arbitrary and brittle.

@brusic
Copy link
Contributor

brusic commented Dec 11, 2013

I agree with you, which is why I added the last sentence/paragraph. I am currently using the _version method, but would love to move away from it.

My point was rather than having "created": true, it should perhaps be something like "type": "created".

@clintongormley
Copy link

Given that the bulk API now returns an HTTP status code with each entry, i think the consistent way to do this would be the same, ie include status: 201|200

@karmi
Copy link
Contributor

karmi commented Dec 17, 2013

I vote for status: 201, status: 200, status: 404, etc, i.e. using the numerical HTTP status codes.

The biggest benefit is that we don't have to invent any names and everybody can translate these codes to meaningful values themselves easily, potentially even leveraging existing dictionary in their codebase...

@dadoonet
Copy link
Member

+1 for status: 200 etc...

@honzakral
Copy link
Contributor Author

Fixed by #4635

@javanna javanna removed the v1.0.1 label Feb 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants