You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by "Shalin Shekhar Mangar (Confluence)" <co...@apache.org> on 2013/12/01 05:36:01 UTC

[CONF] Apache Solr Reference Guide > RealTime Get

Space: Apache Solr Reference Guide (https://cwiki.apache.org/confluence/display/solr)
Page: RealTime Get (https://cwiki.apache.org/confluence/display/solr/RealTime+Get)

Change Comment:
---------------------------------------------------------------------
SOLR-5499: Added note on problems in SolrCloud on disabling this handler

Edited by Shalin Shekhar Mangar:
---------------------------------------------------------------------
For index updates to be visible (searchable), some kind of commit must reopen a searcher to a new point-in-time view of the index. The *realtime get* feature allows retrieval (by {{unique-key}}) of the latest version of any documents without the associated cost of reopening a searcher. This is primarily useful when using Solr as a NoSQL data store and not just a search index. 

Realtime Get currently relies on the update log feature, which is enabled by default. It relies on an update log, which is configured in {{solrconfig.xml}}, in a section like: 

{code:xml|borderStyle=solid|borderColor=#666666}
<updateLog>
   <str name="dir">${solr.ulog.dir:}</str>
</updateLog>
{code}

The latest {{example solrconfig.xml}} should also have a request handler named {{/get}} already defined like the following:
{code:xml|borderStyle=solid|borderColor=#666666}
<requestHandler name="/get" class="solr.RealTimeGetHandler">
     <lst name="defaults">
       <str name="omitHeader">true</str>
       <str name="wt">json</str>
       <str name="indent">true</str>
     </lst>
  </requestHandler>
{code}

Start (or restart) the Solr server, and then index a document:

{code:xml|borderStyle=solid|borderColor=#666666}
curl 'http://localhost:8983/solr/update/json?commitWithin=10000000'
  -H 'Content-type:application/json' -d '[{"id":"mydoc","title":"realtime-get test!"}]'
{code}

If you do a normal search, this document should not be found:

{code:xml|borderStyle=solid|borderColor=#666666}
http://localhost:8983/solr/select?q=id:mydoc
...
"response":
{"numFound":0,"start":0,"docs":[]}
{code}

However if you use the realtime get handler exposed at {{/get}}, you should be able to retrieve that document:

{code:xml|borderStyle=solid|borderColor=#666666}
http://localhost:8983/solr/get?id=mydoc
...
{"doc":{"id":"mydoc","title":"realtime-get test!"]}}
{code}

You can also specify multiple documents at once via the *ids* parameter and a comma separated list of ids, or by using multiple *id* parameters. If you specify multiple ids, or use the *ids* parameter, the response will mimic a normal query response to make it  easier for existing clients to parse. Since you've only indexed one document, the following equivalent examples just repeat the same id.

{code:xml|borderStyle=solid|borderColor=#666666}
http://localhost:8983/solr/get?ids=mydoc,mydoc
http://localhost:8983/solr/get?id=mydoc&id=mydoc
...
{"response":
   {"numFound":2,"start":0,"docs":
     [ { "id":"mydoc", "title":["realtime-get test!"]},
       { "id":"mydoc", "title":["realtime-get test!"]}]
   }
}
{code}

{note}
Do *NOT* disable the realtime get handler at {{/get}} if you are using SolrCloud otherwise any leader election will cause a full sync in *ALL* replicas for the shard in question. Similarly, a replica recovery will also always fetch the complete index from the leader because a partial sync will not be possible in the absence of this handler.
{note}

{scrollbar}


Stop watching space: https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=solr
Change email notification preferences: https://cwiki.apache.org/confluence/users/editmyemailsettings.action