RealTime Get
インデックスの更新を可視化(検索可能にする)するには、何らかのコミットで検索担当者をインデックスの新しい時点のビューに再度開放する必要があります。
リアルタイム取得機能を使用すると、検索担当者を再開放する関連コストなしで、ドキュメントの最新バージョンを(unique-key
で)取得できます。これは、Solr を検索インデックスだけではなく NoSQL データストアとして使用する場合に特に役立ちます。
リアルタイム取得は、デフォルトで有効になっている更新ログ機能に依存しており、solrconfig.xml
で構成できます。
<updateLog>
<str name="dir">${solr.ulog.dir:}</str>
</updateLog>
リアルタイム取得リクエストは、Solr に暗黙的に存在する/get
ハンドラを使用して実行できます。- 暗黙的なリクエストハンドラ - 次の構成に相当します。
<requestHandler name="/get" class="solr.RealTimeGetHandler">
<lst name="defaults">
<str name="omitHeader">true</str>
</lst>
</requestHandler>
たとえば、bin/solr -e techproducts
サンプルコマンドを使用して Solr を開始した場合、次のようにコミットせずに新しいドキュメントをインデックス化できます。
curl 'https://127.0.0.1:8983/solr/techproducts/update/json?commitWithin=10000000' \
-H 'Content-type:application/json' -d '[{"id":"mydoc","name":"realtime-get test!"}]'
このドキュメントを検索しても、まだ見つからないはずです。
https://127.0.0.1:8983/solr/techproducts/query?q=id:mydoc
{"response":
{"numFound":0,"start":0,"docs":[]}
}
ただし、/get
に公開されているリアルタイム取得ハンドラを使用すると、ドキュメントを取得できます。
V1 API
https://127.0.0.1:8983/solr/techproducts/get?id=mydoc
{"doc": {
"id": "mydoc",
"name": "realtime-get test!",
"_version_": 1487137811571146752
}
}
V2 API
https://127.0.0.1:8983/api/collections/techproducts/get?id=mydoc
{"doc": {
"id": "mydoc",
"name": "realtime-get test!",
"_version_": 1487137811571146752
}
}
また、ids
パラメータとコンマ区切りされた ID のリスト、または複数のid
パラメータを使用して、複数のドキュメントを一度に指定することもできます。複数の ID を指定するか、ids
パラメータを使用すると、既存のクライアントが解析しやすくなるように、応答は通常のクエリ応答を模倣します。
たとえば
V1 API
https://127.0.0.1:8983/solr/techproducts/get?ids=mydoc,IW-02
https://127.0.0.1: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"
}
]
}
}
V2 API
https://127.0.0.1:8983/api/collections/techproducts/get?ids=mydoc,IW-02
https://127.0.0.1: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"
}
]
}
}
リアルタイム取得リクエストは、fq
パラメータで指定されたフィルタクエリと組み合わせることもできます。
V1 API
https://127.0.0.1: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}
]
}
}
V2 API
https://127.0.0.1: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}
]
}
}
SolrCloud を使用している場合は、 同様に、このハンドラがない場合、レプリカの復旧でも必ずリーダーから完全なインデックスが取得されます。これは、部分同期が不可能になるためです。 |