I am a SolrJ beginner and want to find out whats the fastest way to determine if an document with an unique ID exists? I don't need the document, I just want to find out if it is already in the index.
Now I try something like this in SolrJ:
private boolean solrContainsId(final String id) {
SolrQuery query = new SolrQuery("id:" + id);
try {
long count = server.query(query).getResults().getNumFound();
return count > 0;
} catch (SolrServerException e) {
return false;
}
}
I think there will be better (faster?) ways which don't need scoring etc. ...
Instead of searching for id equals, use the filter query which would not have any scoring as well would enable to use the fieldcache
SolrQuery query = new SolrQuery();
query.addFilterQuery("id:"+id);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With