Skip to content

手动解压hanlp插件到${ES_HOME}/plugins,需要将${hanlp_home}/config目录拷贝到${ES_HOME}/config/analysis_hanlp目录下 #95

Open
@guluo2016

Description

@guluo2016

问题

我通过解压hanlp zip包到plugins目录下的方式去安装该插件,安装后重启,发现报错如下:
hanlp错误信息

通过分析发现,在加载hanlp插件的时候,是去${ES_HOME}/config目录下加载hanlp.propertieshanlp-remote.xml文件,源代码如下:

private Dictionary(Configuration configuration) {
       //去${ES_HOME}/config下的analysis_hanlp目录下加载配置文件
       Path configDir = configuration.getEnvironment().configFile().resolve(AnalysisHanLPPlugin.PLUGIN_NAME);
       Predefine.HANLP_PROPERTIES_PATH = configDir.resolve(CONFIG_FILE_NAME).toString();
       logger.debug("hanlp properties path: {}", Predefine.HANLP_PROPERTIES_PATH);
       DictionaryFileCache.configCachePath(configuration);
       DictionaryFileCache.loadCache();
       RemoteDictConfig.initial(configDir.resolve(REMOTE_CONFIG_FILE_NAME).toString());
}

解决办法

第一种
将${hanlp_home}/config目录拷贝到${ES_HOME}/config/analysis_hanlp目录下,重启ES集群
第二种
修改代码,将加载hanlp配置文件的路径修改为${hanlp_home}/config

 private Dictionary(Configuration configuration) {
        # 从${hanlp_home}/config目录下加载
        Path hanlpPluginConfigDir = configuration.getEnvironment().pluginsFile().resolve(AnalysisHanLPPlugin.PLUGIN_NAME + "/config");
        Predefine.HANLP_PROPERTIES_PATH = hanlpPluginConfigDir.resolve(CONFIG_FILE_NAME).toString();
        logger.debug("hanlp properties path: {}", Predefine.HANLP_PROPERTIES_PATH);
        DictionaryFileCache.configCachePath(configuration);
        DictionaryFileCache.loadCache();
        RemoteDictConfig.initial(hanlpPluginConfigDir.resolve(REMOTE_CONFIG_FILE_NAME).toString());
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions