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
Add search-exists API to check if any matching documents exist for a given query #7026
Conversation
The request format would be identical to that of the Count API: curl -XGET 'http://localhost:9200/_exists' -d '
{
"query" : {
...
}
}' Additionally one can specify The Response would be as simple as: {
"exists": true,
"_shards": {
...
}
} I have intentionally not integrated it with the |
TODO:
|
Updated PR:
TODO:
|
@clintongormley would be awesome if you could take a look at the docs for the new API. The docs are quite similar to that of the count API. TODO:
|
Hi @areek This looks good, but I think the REST API needs to change to be consistent. Exists requests in the REST layer are implemented as HEAD requests which don't return a body, just a 200 or a 404. (they can return other HTTP error codes if some other error occurs) I think this should be:
And in the rest specs, it should probably be called |
@clintongormley I changed the REST API to handle Regarding the naming, I was thinking |
@clintongormley As far as I have seen, it seems like we don't have an explicit 'exists' API. I am assuming you are referring to The updated REST resp/request are as follows: curl -XHEAD -i "localhost:9200/{index|null}/{type|null}/_exists" -d '
{
"query": ...
}
'
or
curl -XHEAD -i "localhost:9200/{index|null}/{type|null}/_exists?q=.." The HTTP The response header is a simple: HTTP/1.1 200 OK
Content-Type: text/plain; charset=UTF-8
Content-Length: 0 or HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=UTF-8
Content-Length: 0 The response will not have any content for any of the supported HTTP methods. |
@areek Bah, I'd completely forgotten about the issue with HEAD and bodies! Apologies. And yes, by "exists" API I was referring to OK, so rethinking this: We already have Also, the clients expect a body in the response for all requests except for HEAD requests, but as you've pointed out, eg the JS client won't be able to use a HEAD request here, so it looks like returning a body will be required. Sorry for the runaround |
aside of @clintongormley comments this looks fantastic! |
@clintongormley I have updated the REST req/res as follows:
{
"exists" : true | false
}
|
@@ -0,0 +1,97 @@ | |||
[[search-exists]] | |||
== Exists API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call this the "Search Exists API" to make it clear which "exists" functionality it refers to in the docs search dropdown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to Search Exists API.
Hi @areek I'm tempted to remove support for HEAD and for
So I think this should be exposed only as :
|
also, the response body looks good. |
Hi @clintongormley thanks for the review. I have updated the documentation and the REST endpoints as suggested. |
LGTM |
I think this is ready. I will commit this soon, if there are no objections. |
… query Implements a new Exists API allowing users to do fast exists check on any matched documents for a given query. This API should be faster then using the Count API as it will: - early terminate the search execution once any document is found to exist - return the response as soon as the first shard reports matched documents closes elastic#6995
Implements a new Exists API allowing users to do fast exists check on any matched documents for a given query.
This API should be faster then using the Count API as it will:
closes #6995