Luke工具查看Lucene创建的索引时:Format version is not supported

博客讲述了在使用Lucene 9.1.0创建索引后,尝试用Luke工具查看时遇到的问题。错误信息提示索引格式版本不支持,原因可能是Lucene版本高于Luke工具能识别的范围。通过降低Lucene版本到7.7.3,成功解决了Luke工具无法读取索引的问题,强调了版本匹配在软件兼容性中的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 问题描述

使用Lucense 9.1.0 创建索引并搜索,程序OK,但是使用Luck工具进行查看时出现异常信息:org.apache.lucene.index.IndexFormatTooNewException: Format version is not supported (resource BufferedChecksumIndexInput(MMapIndexInput(path=“D:\lucene_index\segments_1”))): 10 (needs to be between 7 and 9)

[2022-05-02T10:08:16,654]  WARN (IndexUtils.java:85) - Format version is not supported (resource BufferedChecksumIndexInput(MMapIndexInput(path="D:\lucene_index\segments_1"))): 10 (needs to be between 7 and 9)
org.apache.lucene.index.IndexFormatTooNewException: Format version is not supported (resource BufferedChecksumIndexInput(MMapIndexInput(path="D:\lucene_index\segments_1"))): 10 (needs to be between 7 and 9)
	at org.apache.lucene.codecs.CodecUtil.checkHeaderNoMagic(CodecUtil.java:216) ~[luke-swing-with-deps.jar:?]
	at org.apache.lucene.index.SegmentInfos.readCommit(SegmentInfos.java:305) ~[luke-swing-with-deps.jar:?]
	at org.apache.lucene.index.SegmentInfos.readCommit(SegmentInfos.java:289) ~[luke-swing-with-deps.jar:?]
	at org.apache.lucene.index.StandardDirectoryReader$1.doBody(StandardDirectoryReader.java:61) ~[luke-swing-with-deps.jar:?]
	at org.apache.lucene.index.StandardDirectoryReader$1.doBody(StandardDirectoryReader.java:58) ~[luke-swing-with-deps.jar:?]
	at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:680) ~[luke-swing-with-deps.jar:?]
	at org.apache.lucene.index.StandardDirectoryReader.open(StandardDirectoryReader.java:81) ~[luke-swing-with-deps.jar:?]
	at org.apache.lucene.index.DirectoryReader.open(DirectoryReader.java:63) ~[luke-swing-with-deps.jar:?]
	at org.apache.lucene.luke.models.util.IndexUtils$1.preVisitDirectory(IndexUtils.java:82) ~[luke-swing-with-deps.jar:?]
	at org.apache.lucene.luke.models.util.IndexUtils$1.preVisitDirectory(IndexUtils.java:77) ~[luke-swing-with-deps.jar:?]
	at java.nio.file.Files.walkFileTree(Files.java:2732) ~[?:?]
	at java.nio.file.Files.walkFileTree(Files.java:2797) ~[?:?]
	at org.apache.lucene.luke.models.util.IndexUtils.openIndex(IndexUtils.java:77) ~[luke-swing-with-deps.jar:?]
	at org.apache.lucene.luke.app.IndexHandler.open(IndexHandler.java:68) ~[luke-swing-with-deps.jar:?]
	at org.apache.lucene.luke.app.desktop.components.dialog.menubar.OpenIndexDialogFactory$ListenerFunctions.openIndexOrDirectory(OpenIndexDialogFactory.java:341) ~[luke-swing-with-deps.jar:?]
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967) ~[?:?]
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308) ~[?:?]
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405) ~[?:?]
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262) ~[?:?]
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279) ~[?:?]
	at java.awt.Component.processMouseEvent(Component.java:6635) ~[?:?]
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3342) ~[?:?]
	at java.awt.Component.processEvent(Component.java:6400) ~[?:?]
	at java.awt.Container.processEvent(Container.java:2263) ~[?:?]
	at java.awt.Component.dispatchEventImpl(Component.java:5011) ~[?:?]
	at java.awt.Container.dispatchEventImpl(Container.java:2321) ~[?:?]
	at java.awt.Component.dispatchEvent(Component.java:4843) ~[?:?]
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918) ~[?:?]
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547) ~[?:?]
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488) ~[?:?]
	at java.awt.Container.dispatchEventImpl(Container.java:2307) ~[?:?]
	at java.awt.Window.dispatchEventImpl(Window.java:2772) ~[?:?]
	at java.awt.Component.dispatchEvent(Component.java:4843) ~[?:?]
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772) ~[?:?]
	at java.awt.EventQueue$4.run(EventQueue.java:721) ~[?:?]
	at java.awt.EventQueue$4.run(EventQueue.java:715) ~[?:?]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:?]
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85) ~[?:?]
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95) ~[?:?]
	at java.awt.EventQueue$5.run(EventQueue.java:745) ~[?:?]
	at java.awt.EventQueue$5.run(EventQueue.java:743) ~[?:?]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:?]
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85) ~[?:?]
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:742) ~[?:?]
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) ~[?:?]
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) ~[?:?]
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:117) ~[?:?]
	at java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:190) ~[?:?]
	at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:235) ~[?:?]
	at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:233) ~[?:?]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:?]
	at java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:233) ~[?:?]
	at java.awt.Dialog.show(Dialog.java:1070) ~[?:?]
	at java.awt.Component.show(Component.java:1716) ~[?:?]
	at java.awt.Component.setVisible(Component.java:1663) ~[?:?]
	at java.awt.Window.setVisible(Window.java:1031) ~[?:?]
	at java.awt.Dialog.setVisible(Dialog.java:1005) ~[?:?]
	at org.apache.lucene.luke.app.desktop.util.DialogOpener.open(DialogOpener.java:44) ~[luke-swing-with-deps.jar:?]
	at org.apache.lucene.luke.app.desktop.util.DialogOpener.open(DialogOpener.java:37) ~[luke-swing-with-deps.jar:?]
	at org.apache.lucene.luke.app.desktop.components.MenuBarProvider$ListenerFunctions.showOpenIndexDialog(MenuBarProvider.java:190) ~[luke-swing-with-deps.jar:?]
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967) [?:?]
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308) [?:?]
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405) [?:?]
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262) [?:?]
	at javax.swing.AbstractButton.doClick(AbstractButton.java:369) [?:?]
	at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1020) [?:?]
	at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1064) [?:?]
	at java.awt.Component.processMouseEvent(Component.java:6635) [?:?]
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3342) [?:?]
	at java.awt.Component.processEvent(Component.java:6400) [?:?]
	at java.awt.Container.processEvent(Container.java:2263) [?:?]
	at java.awt.Component.dispatchEventImpl(Component.java:5011) [?:?]
	at java.awt.Container.dispatchEventImpl(Container.java:2321) [?:?]
	at java.awt.Component.dispatchEvent(Component.java:4843) [?:?]
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918) [?:?]
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547) [?:?]
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488) [?:?]
	at java.awt.Container.dispatchEventImpl(Container.java:2307) [?:?]
	at java.awt.Window.dispatchEventImpl(Window.java:2772) [?:?]
	at java.awt.Component.dispatchEvent(Component.java:4843) [?:?]
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772) [?:?]
	at java.awt.EventQueue$4.run(EventQueue.java:721) [?:?]
	at java.awt.EventQueue$4.run(EventQueue.java:715) [?:?]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:?]
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85) [?:?]
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95) [?:?]
	at java.awt.EventQueue$5.run(EventQueue.java:745) [?:?]
	at java.awt.EventQueue$5.run(EventQueue.java:743) [?:?]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:?]
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85) [?:?]
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:742) [?:?]
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) [?:?]
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) [?:?]
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) [?:?]
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) [?:?]
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) [?:?]
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:90) [?:?]
[2022-05-02T10:08:16,654] ERROR (IndexHandler.java:70) - No valid directory at the location: D:\lucene_index
java.lang.RuntimeException: No valid directory at the location: D:\lucene_index

2. 问题分析

2.1 推测原因

根据 Format version is not supported推测,可能原因是:Lucense版本与Luke工具版本不匹配。

2.2 验证猜想
2.1 下载最新的Luke工具

Luke工具下载地址:Luke
Lucense 官网链接:Lucense

使用Luke工具打开index文件夹,仍然报错。
luke报错
去查看github 中luke工具的readme文档之后,发现该工具已经不再维护了。
在这里插入图片描述
从这可知,原因肯定是Lucense版本太高了,Luke工具版本太低了,不支持而已。

故,降低Lucense版本,使用Lucense 7.7.3版本生成索引,在使用Luke工具打开。

  <dependencies>
    <!--  添加lucene 的依赖  -->
    <dependency>
      <groupId>org.apache.lucene</groupId>
      <artifactId>lucene-core</artifactId>
      <version>7.7.3</version>
    </dependency>

    <dependency>
      <groupId>org.apache.lucene</groupId>
      <artifactId>lucene-analyzers-common</artifactId>
      <version>7.7.3</version>
    </dependency>

    <dependency>
      <groupId>org.apache.lucene</groupId>
      <artifactId>lucene-queryparser</artifactId>
      <version>7.7.3</version>
    </dependency>
  </dependencies>

在这里插入图片描述

2.3 问题原因

Lucense 版本太高,建立的索引,低版本Luke工具是无法支持的,并且Luke工具已经不在维护。

2.4 解决版本

降低Lucense版本 & Luke工具版本匹配。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值