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.
For more options, visit https://groups.google.com/d/optout.