本文讲述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"</