我的用例:我目前使用 solr 5.5 并升级到 solr 8.8
为此,我需要在所有安装 solr 的机器上重新建立索引。我需要检查索引版本,如果索引是从旧版本创建的,那么我将运行重新索引逻辑,如果它已经是新版本,我将跳过重新索引。
有办法检测索引版本吗?
注意:配置文件已更新到新版本,因此无法使用 solrconfig.xml 中的标签
HTTP GET 请求检索信息:
yoursolrhost:8983/solr/admin/info/system
会像下面这样
http://yoursolrhost:8983/solr/admin/info/system?wt=json
如果您可以直接访问文件系统上的索引,则可以尝试使用 lucene CheckIndex Tool。
java -cp lucene-core-9.3.0.jar:lucene-backward-codecs-9.3.0.jar org.apache.lucene.index.CheckIndex /path/to/index/
然后您应该在输出中看到索引版本:
Checking index with threadCount: 12
0.78% total deletions; 290597 documents; 2255 deletions
Segments file=segments_7d numSegments=13 version=8.11.1 id=bmwtml5nan76oxh53jblk3hjg userData={commitCommandVer=1729352676019273728, commitTimeMSec=1649239231128}
1 of 13: name=_2us maxDoc=2
version=8.11.1
id=2alyagqpio6wye81jr09czfg9
codec=Lucene87
compound=false
numFiles=18
size (MB)=0.036
diagnostics = {java.version=1.8.0_312, java.vm.version=25.312-b07, lucene.version=8.11.1, source=flush, os.arch=amd64, java.runtime.version=1.8.0_312-8u312-b07-0ubuntu1~20.04-b07, os.version=5.4.0-107-generic, java.vendor=Private Build, os=Linux, timestamp=1648810655017}
在此示例中,我使用版本 9 中的工具来检查使用版本 8 创建的索引。 但请记住:您使用的库可能只与当前 + 以前的 lucene 索引版本兼容。因此,如果您使用 lucene 9 中的 JAR,它将可以检查 9+8 中的索引,但不能检查 7 中的索引。
另请参阅: https://lucene.apache.org/core/9_3_0/core/org/apache/lucene/index/CheckIndex.html
(用法与文档中介绍的IndexUpgrader类似:) https://solr.apache.org/guide/solr/latest/deployment-guide/indexupgrader-tool.html