kuzzleio / kuzzle

Open-source Back-end, self-hostable & ready to use - Real-time, storage, advanced search - Web, Apps, Mobile, IoT -
https://kuzzle.io
Apache License 2.0
1.44k stars 124 forks source link

Have an Kuzzle API route with search arguments but with a document:get behavior #1032

Closed dbengsch closed 6 years ago

dbengsch commented 6 years ago

As a plugin developper, I often have to use a document:search request to get the first result of the hits (with from = 0 and size = 1). As the search route mostly results to a success (status_code = 200) even if there is no result, I have to check manually if the result set contains a result and get it from the result hits. It makes an usual fetch and let the API fail scenario impossible as soon as you can't forecast the document _id you want to fetch. I have to forge a NotFoundError manually, instead of relying on the error coming from the API.

It would be great to provide a route that takes query and sort as parameters and provide a single document as result directly in the body, or a 404 status code if there is no result.

This new route could be called document:getFirst

The document:search route could also return a 404 error if no result is returned but it might come with a lot of hassles considering from and size parameters; a search could be legit and have a total greater than 0 but have no result depending on the from and size parameters...

Aschen commented 6 years ago

https://jira.kaliop.net/browse/KZL-292