【应用】Apache Solr

本文详细介绍了Apache Solr 8.5.1的单机部署过程,包括创建Solr Home目录、启动及配置Solr服务器、创建Core、导入数据并配置DataImportHandler(DIH)从JDBC数据库导入数据,同时讲解了如何处理数据库密码加密和查询操作。
摘要由CSDN通过智能技术生成

本文讲述Apache Solr 8.5.1的单机应用。

创建Solr Home目录

在本地电脑上创建一个F:\blog-solr的目录作为主目录,将solr-8.5.1\server\solr\solr.xml复制到F:\blog-solr下。

启动

指定启动端口,指定Solr Home目录,在solr-8.5.1\bin目录下输入solr start -p 8983 -s F:\blog-solr启动Solr服务器。

修改默认端口

Windows下,打开solr-8.5.1\bin\solr.cmd

有一段描述参数信息的:

-p port    Specify the port to start the Solr HTTP listener on; default is 8983
"             The specified port (SOLR_PORT) will also be used to determine the stop port"
"             STOP_PORT=(\$SOLR_PORT-1000) and JMX RMI listen port RMI_PORT=(\$SOLR_PORT+10000). "
"             For instance, if you set -p 8985, then the STOP_PORT=7985 and RMI_PORT=18985"

找到下面一段代码,修改默认端口为8081

IF "%SOLR_PORT%"=="" set SOLR_PORT=8081

修改默认Solr Home

Windows下,打开solr-8.5.1\bin\solr.cmd

-s dir    Sets the solr.solr.home system property; Solr will create core directories under
            this directory. This allows you to run multiple Solr instances on the same host
            while reusing the same server directory set using the -d parameter. If set, the
            specified directory should contain a solr.xml file, unless solr.xml exists in Zookeeper.
            This parameter is ignored when running examples (-e), as the solr.solr.home depends
            on which example is run. The default value is server/solr. If passed a relative dir
            validation with the current dir will be done before trying the default server/^<dir^>

找到下面一段代码,将默认Solr Home目录改为F:\blog-solr

:start_solr
IF "%SOLR_HOME%"=="" set "SOLR_HOME=F:\blog-solr"
IF EXIST "%cd%\%SOLR_HOME%" set "SOLR_HOME=%cd%\%SOLR_HOME%"

IF NOT EXIST "%SOLR_HOME%\" (
  IF EXIST "%SOLR_SERVER_DIR%\%SOLR_HOME%" (
    set "SOLR_HOME=%SOLR_SERVER_DIR%\%SOLR_HOME%"
  ) ELSE (
    set "SCRIPT_ERROR=Solr home directory %SOLR_HOME% not found!"
    goto err
  )
)

创建Core

打开浏览器输入http://localhost:8983/,进入Solr Admin管理控制台。

点击左边的Core Admin,展示添加Core的弹窗。

修改name值为article_core,instanceDir值为article_core,schema值为managed-schema

点击Add Core按钮,然后就弹出一串错误信息:

Error CREATEing SolrCore ‘article_core’: Unable to create core [article_core] Caused by: Can’t find resource ‘solrconfig.xml’ in classpath or ‘F:\blog-solr\article_core’

意思是在F:\blog-solr\article_core目录下没有找到solrconfig.xml文件,创建article_core失败。

solr-8.5.1\server\solr\configsets\_default下的conf目录复制到F:\blog-solr\article_core\目录下。

点击Add Core按钮,创建article_core就成功了,在F:\blog-solr\article_core\目录下会创建一个core.properties文件和data文件夹。

打开F:\blog-solr\article_core\core.properties文件,将schema=schema.xml改成schema=managed-schema

导入数据

点击左侧的下拉框,选择article_core,选择Dataimport

提示信息:The solrconfig.xml file for this index does not have an operational DataImportHandler defined!

意思是solrconfig.xml文件中没有定义DataImportHandler。

配置DIH

在solrconfig.xml文件中配置DIH

参考官方文档Uploading Structured Data Store Data with the Data Import Handler

solrconfig.xml中配置DataImportHandler,定义在<conf>标签内:

<requestHandler name="/dataimport"</
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值