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...
As a plugin developper, I often have to use a
document:search
request to get the first result of thehits
(withfrom = 0
andsize = 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 resulthits
. It makes an usualfetch 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
andsort
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 consideringfrom
andsize
parameters; a search could be legit and have atotal
greater than 0 but have no result depending on the from and size parameters...