Is there an exists API or something like that?

Hi All,

I noticed that there is a count API, that is basically a query without
scoring, but only count the #hits.

Now I need to know whether a query has results or not.
Of course I can do that by doing a count and then test of 0 results, but
that is probably not the most efficient approach.

Also the exists filter seems no to solve this problem.

Any idea's?

/P

--
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 elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Executing a query, plus the network latency, will be far greater than any
time used on the client side to see the count is 0 or not. The query needs
to be executed regardless to determine if it will return a result. I would
simply use the count API.

--
Ivan

On Mon, Sep 23, 2013 at 6:22 AM, Peter van der Weerd pw2@bitmanager.nlwrote:

Hi All,

I noticed that there is a count API, that is basically a query without
scoring, but only count the #hits.

Now I need to know whether a query has results or not.
Of course I can do that by doing a count and then test of 0 results, but
that is probably not the most efficient approach.

Also the exists filter seems no to solve this problem.

Any idea's?

/P

--
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 elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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 elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

There is a search_type "count" (not count API!) which is the fastest method
to check for search results.

http://www.elasticsearch.org/guide/reference/api/search/search-type/

Jörg

--
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 elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

What about asking for one result and no fields? Is it still faster to count all the results?

Sent from my iPhone

On Sep 23, 2013, at 7:44 PM, "joergprante@gmail.com" joergprante@gmail.com wrote:

There is a search_type "count" (not count API!) which is the fastest method to check for search results.

Elasticsearch Platform — Find real-time answers at scale | Elastic

Jörg

--
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 elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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 elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Peter,

At the moment, there is no option to just check if query matches any
documents other then using the count API or the count search type and
checking #hits > 0. In Lucene you could use early termination
(CollectionTerminatedException) to stop enumerating docs when the first
document is found - so we can do something there.

If the #hits>0 is not fast enough for you, I suggest you open an issue,
including and example of your use case, the timing involved and why they
are not good enough for you.

Of course, you can also have some fun writing a plugin/a pull request with
an extra endpoint (modelled after the Count API) and see how much that
helps. Shouldn't be too hard and is a nice exercise :slight_smile:

Cheers,
Boaz

On Monday, September 23, 2013 3:22:20 PM UTC+2, Peter van der Weerd wrote:

Hi All,

I noticed that there is a count API, that is basically a query without
scoring, but only count the #hits.

Now I need to know whether a query has results or not.
Of course I can do that by doing a count and then test of 0 results, but
that is probably not the most efficient approach.

Also the exists filter seems no to solve this problem.

Any idea's?

/P

--
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 elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Even when a single document is requested, all matching documents will be
collected in order to count the number of matches. The count API can be
expected to be slightly faster than collecting a single document since
Elasticsearch will be able to use a specialized collector that only counts
matches and doesn't care about scoring or field values.

--
Adrien Grand

--
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 elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.