"limit" is not a limit for response size. It sets a shard limit which is
quite low level, so the resources per shard of ES are not so much under
pressure. If the sum of the limits on the shards matches the total length
of the response is not guaranteed.
The limit parameter for the response is the "size" parameter. Can you try
POST profiles/profile/_search
{
"size" : 1,
"query": {
"constant_score" : {
"filter" : {
"term": {
"profile_id": "salinger-23145"
}
}
}
}
}
and see if this works better?
If you want to perform a true existence check of a doc, you should use the
doc _id and a head request, something like
HEAD profiles/profile/id
which is faster than a search.
Jörg
On Wed, Oct 22, 2014 at 8:58 PM, Jeff Gandt <[email protected]> wrote:
> I have a query that I want to return only one document. Basically, I want
> to do an existence check on a document with a given term filter.
>
> I am executing:
>
> POST profiles/profile/_search
> {
> "query": {
> "filtered": {
> "filter": {
> "bool": {
> "must": [
> {
> "limit": {
> "value": 1
> }
> },
> {
> "term": {
> "profile_id": "salinger-23145"
> }
> }
> ]
> }
> }
> }
> }
> }
>
> The profiles/profile mapping has tens of millions of documents in it, two
> of which match the given terms query (when the limit is removed entirely).
>
> When I execute the query, I get zero results back. However, If I change
> the limit value to two (2) then one (1) result is returned. If I change the
> limit value to three (3) then two (2) results are returned. It's almost
> like there is an off by one error in limit.
>
> So am I:
>
> 1) Writing the query wrong?
> I tried placing the limit outside of the must, bool, and filter clauses.
> That caused errors in each case. But I may have just done something silly.
>
> 2) Misunderstanding limit?
> My understanding of limit is that it returns no more than x documents per
> shard. Given that I have five shards and at least two documents matching
> the query, I should be returning between one and five documents. However,
> looking at the limit documentation
> <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-limit-filter.html>
> I
> suspect that I may be misunderstanding how limit works. The wording "to
> execute on" leads me to believe that it may only be selecting ONE document
> against which the term filter is run. Thus, if the one document that it
> tests doesn't match, it returns zero results. However, the limit 2
> returning one document leads me to believe that my original understanding
> is correct.
>
> 3) Staring at an elasticsearch limit bug?
> Unfortunately I have been unable to reproduce the error after creating
> test indexes and mappings. The limit behaves exactly as I expect in every
> other case.
>
> 4) Doing something else that is equally silly?
>
> Any help or suggestions is appreciated. Can I provide any clarifications?
>
> Thanks,
>
> .jpg
>
> --
> You received this message because you are subscribed to the Google Groups
> "elasticsearch" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/86988787-fb31-4b5a-b570-427750177ecd%40googlegroups.com
> <https://groups.google.com/d/msgid/elasticsearch/86988787-fb31-4b5a-b570-427750177ecd%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CAKdsXoG1iiuwKQcysvh%2BBVtLGeEPrj89F%3DR4syTVRBt-bru9oQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.