RealTime Get

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.

Real Time Get relies on the update log feature, which is enabled by default and can be configured in solrconfig.xml:

<updateLog>
  <str name="dir">${solr.ulog.dir:}</str>
</updateLog>

Real Time Get requests can be performed using the /get handler which exists implicitly in Solr - see Implicit Request Handlers - it’s equivalent to the following configuration:

<requestHandler name="/get" class="solr.RealTimeGetHandler">
  <lst name="defaults">
    <str name="omitHeader">true</str>
  </lst>
</requestHandler>

For example, if you started Solr using the bin/solr start -e techproducts example command, you could then index a new document without committing it, like so:

curl 'http://localhost:8983/solr/techproducts/update/json?commitWithin=10000000' \
  -H 'Content-type:application/json' -d '[{"id":"mydoc","name":"realtime-get test!"}]'

If you search for this document, it should not be found yet:

http://localhost:8983/solr/techproducts/query?q=id:mydoc
{"response":
  {"numFound":0,"start":0,"docs":[]}
}

However if you use the Real Time Get handler exposed at /get, you can retrieve the document:

  • V1 API

  • V2 API

http://localhost:8983/solr/techproducts/get?id=mydoc
{"doc": {
  "id": "mydoc",
  "name": "realtime-get test!",
  "_version_": 1487137811571146752
  }
}
http://localhost:8983/api/collections/techproducts/get?id=mydoc
{"doc": {
  "id": "mydoc",
  "name": "realtime-get test!",
  "_version_": 1487137811571146752
  }
}

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.

For example:

  • V1 API

  • V2 API

http://localhost:8983/solr/techproducts/get?ids=mydoc,IW-02
http://localhost:8983/solr/techproducts/get?id=mydoc&id=IW-02
{"response":
  {"numFound":2,"start":0,"docs":
    [ { "id":"mydoc",
        "name":"realtime-get test!",
        "_version_":1487137811571146752},
      {
        "id":"IW-02",
        "name":"iPod & iPod Mini USB 2.0 Cable"
      }
    ]
 }
}
http://localhost:8983/api/collections/techproducts/get?ids=mydoc,IW-02
http://localhost:8983/api/collections/techproducts/get?id=mydoc&id=IW-02
{"response":
  {"numFound":2,"start":0,"docs":
    [ { "id":"mydoc",
        "name":"realtime-get test!",
        "_version_":1487137811571146752},
      {
        "id":"IW-02",
        "name":"iPod & iPod Mini USB 2.0 Cable"
      }
    ]
 }
}

Real Time Get requests can also be combined with filter queries, specified with an fq parameter:

  • V1 API

  • V2 API

http://localhost:8983/solr/techproducts/get?id=mydoc&id=IW-02&fq=name:realtime-get
{"response":
  {"numFound":1,"start":0,"docs":
    [ { "id":"mydoc",
        "name":"realtime-get test!",
        "_version_":1487137811571146752}
    ]
 }
}
http://localhost:8983/api/collections/techproducts/get?id=mydoc&id=IW-02&fq=name:realtime-get
{"response":
  {"numFound":1,"start":0,"docs":
    [ { "id":"mydoc",
        "name":"realtime-get test!",
        "_version_":1487137811571146752}
    ]
 }
}

Do NOT disable the realtime get handler at /get if you are using SolrCloud. Doing so will result in any leader election to 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.