| = RealTime Get |
| // Licensed to the Apache Software Foundation (ASF) under one |
| // or more contributor license agreements. See the NOTICE file |
| // distributed with this work for additional information |
| // regarding copyright ownership. The ASF licenses this file |
| // to you under the Apache License, Version 2.0 (the |
| // "License"); you may not use this file except in compliance |
| // with the License. You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, |
| // software distributed under the License is distributed on an |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| // KIND, either express or implied. See the License for the |
| // specific language governing permissions and limitations |
| // under the License. |
| |
| 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`: |
| |
| [source,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-requesthandlers.adoc#,Implicit RequestHandlers>> - it's equivalent to the following configuration: |
| |
| [source,xml] |
| ---- |
| <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 -e techproducts` example command, you could then index a new document without committing it, like so: |
| |
| [source,bash] |
| ---- |
| 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: |
| |
| [source,bash] |
| ---- |
| http://localhost:8983/solr/techproducts/query?q=id:mydoc |
| ---- |
| |
| [source,json] |
| ---- |
| {"response": |
| {"numFound":0,"start":0,"docs":[]} |
| } |
| ---- |
| |
| However if you use the Real Time Get handler exposed at `/get`, you can retrieve the document: |
| |
| [.dynamic-tabs] |
| -- |
| [.tab-pane#v1get] |
| ==== |
| [.tab-label]*V1 API* |
| [source,bash] |
| ---- |
| http://localhost:8983/solr/techproducts/get?id=mydoc |
| ---- |
| |
| [source,json] |
| ---- |
| {"doc": { |
| "id": "mydoc", |
| "name": "realtime-get test!", |
| "_version_": 1487137811571146752 |
| } |
| } |
| ---- |
| ==== |
| |
| [.tab-pane#v2get] |
| ==== |
| [.tab-label]*V2 API* |
| [source,bash] |
| ---- |
| http://localhost:8983/api/collections/techproducts/get?id=mydoc |
| ---- |
| |
| [source,json] |
| ---- |
| {"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: |
| |
| [.dynamic-tabs] |
| -- |
| [.tab-pane#v1getids] |
| ==== |
| [.tab-label]*V1 API* |
| [source,bash] |
| ---- |
| http://localhost:8983/solr/techproducts/get?ids=mydoc,IW-02 |
| http://localhost:8983/solr/techproducts/get?id=mydoc&id=IW-02 |
| ---- |
| |
| [source,json] |
| ---- |
| {"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" |
| } |
| ] |
| } |
| } |
| ---- |
| ==== |
| |
| [.tab-pane#v2getids] |
| ==== |
| [.tab-label]*V2 API* |
| [source,bash] |
| ---- |
| http://localhost:8983/api/collections/techproducts/get?ids=mydoc,IW-02 |
| http://localhost:8983/api/collections/techproducts/get?id=mydoc&id=IW-02 |
| ---- |
| |
| [source,json] |
| ---- |
| {"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 <<common-query-parameters.adoc#fq-filter-query-parameter,`fq` parameter>>: |
| |
| [.dynamic-tabs] |
| -- |
| [.tab-pane#v1getfq] |
| ==== |
| [.tab-label]*V1 API* |
| [source,bash] |
| ---- |
| http://localhost:8983/solr/techproducts/get?id=mydoc&id=IW-02&fq=name:realtime-get |
| ---- |
| |
| [source,json] |
| ---- |
| {"response": |
| {"numFound":1,"start":0,"docs": |
| [ { "id":"mydoc", |
| "name":"realtime-get test!", |
| "_version_":1487137811571146752} |
| ] |
| } |
| } |
| ---- |
| ==== |
| |
| [.tab-pane#v2getfq] |
| ==== |
| [.tab-label]*V2 API* |
| [source,bash] |
| ---- |
| http://localhost:8983/api/collections/techproducts/get?id=mydoc&id=IW-02&fq=name:realtime-get |
| ---- |
| |
| [source,json] |
| ---- |
| {"response": |
| {"numFound":1,"start":0,"docs": |
| [ { "id":"mydoc", |
| "name":"realtime-get test!", |
| "_version_":1487137811571146752} |
| ] |
| } |
| } |
| ---- |
| ==== |
| -- |
| |
| [WARNING] |
| ==== |
| 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. |
| ==== |