The realtime get API retrieves the latest versions of one or more documents.
We use the term “realtime” to distinguish it from normal lucene-based search which operates on a snapshot of the index that is periodically refreshed. Realtime get is guaranteed to return the latest version of a document.
Parameters to the realtime-get component, /get
include:
id
– the id of the document to getids
– a list of comma separated document idsfl
– comma separated field list of the document fields to return
Realtime Get Examples
If a single id
parameter is used, a simple single-document response is returned. For example:
$ curl http://localhost:8983/solr/demo/get?id=book1
{ "doc": { "id":"book1", "title":["Jhereg"], "author":"Steven Brust", "_version_":1409590643313868800}}
If the ids
parameter, or multiple id
parameters are used, the response will mimic the document list format used by normal queries. For example:
$ curl http://localhost:8983/solr/demo/get?ids=book1,book2
{ "response":{"numFound":2,"start":0,"docs":[ { "id":"book1", "title":["Jhereg"], "author":"Steven Brust", "_version_":1409590643313868800}, { "id":"book2", "title":["The Black Company"], "author":"Glen Cook", "_version_":1409592850533726900}] }}
Realtime Get with SolrJ
Here’s an example of how to use real-time get with SolrJ, the Solr Java client:
// Note: this example is for Solr 5.1 and later // First, we create the client and point it at the Solr server HttpSolrClient client = new HttpSolrClient("http://localhost:8983/solr/demo"); SolrDocument sdoc = client.getById("book1"); System.out.println("I found book " + sdoc); client.close(); // shut down the client when we are done