官网下载地址
http://lucene.apache.org/solr/downloads.html
完整示例步骤
解压下载的安装包,我使用的jdk是1.8
1.示例步骤:
E:\Solr\solr-7.3.1\bin>solr.cmd start -e cloud
Welcome to the SolrCloud example!
//这个交互式会话将帮助您在本地工作站上启动SolrCloud集群。
//首先,您希望在本地集群中运行多少Solr节点?可以选择1~4个节点,默认是2个(按回车默认是2个节点)
This interactive session will help you launch a SolrCloud cluster on your local workstation.
To begin, how many Solr nodes would you like to run in your local cluster? (specify 1-4 nodes) [2]:
//好,让我们为示例SolrCloud集群启动两个Solr节点。
//请输入node1端口,默认为8983(按回车为默认)
Ok, let's start up 2 Solr nodes for your example SolrCloud cluster.
Please enter the port for node1 [8983]:
//请输入node2节点的端口,默认7574
Please enter the port for node2 [7574]:
Creating Solr home directory E:\Solr\solr-7.3.1\example\cloud\node1\solr
Cloning E:\Solr\solr-7.3.1\example\cloud\node1 into
E:\Solr\solr-7.3.1\example\cloud\node2
Starting up Solr on port 8983 using command:
"E:\Solr\solr-7.3.1\bin\solr.cmd" start -cloud -p 8983 -s "E:\Solr\solr-7.3.1\example\cloud\node1\solr"
Waiting up to 30 to see Solr running on port 8983
Started Solr server on port 8983. Happy searching!
Starting up Solr on port 7574 using command:
"E:\Solr\solr-7.3.1\bin\solr.cmd" start -cloud -p 7574 -s "E:\Solr\solr-7.3.1\example\cloud\node2\solr" -z localhost:9983
Waiting up to 30 to see Solr running on port 7574
Started Solr server on port 7574. Happy searching!
INFO - 2018-07-19 21:38:20.632; org.apache.solr.client.solrj.impl.ZkClientClusterStateProvider; Cluster at localhost:9983 ready
Now let's create a new collection for indexing documents in your 2-node cluster.
Please provide a name for your new collection: [gettingstarted]
techproducts
How many shards would you like to split techproducts into? [2]
How many replicas per shard would you like to create? [2]
Please choose a configuration for the techproducts collection, available options are:
_default or sample_techproducts_configs [_default]
sample_techproducts_configs
Created collection 'techproducts' with 2 shard(s), 2 replica(s) with config-set 'techproducts'
Enabling auto soft-commits with maxTime 3 secs using the Config API
POSTing request to Config API: http://localhost:8983/solr/techproducts/config
{"set-property":{"updateHandler.autoSoftCommit.maxTime":"3000"}}
Successfully set-property updateHandler.autoSoftCommit.maxTime to 3000
SolrCloud example running, please visit: http://localhost:8983/solr
E:\Solr\solr-7.3.1\bin>cd ..
E:\Solr\solr-7.3.1>java -jar -Dc=techproducts -Dauto example\exampledocs\post.jar example\exampledocs\*
SimplePostTool version 5.0.0
Posting files to [base] url http://localhost:8983/solr/techproducts/update...
Entering auto mode. File endings considered are xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log
POSTing file books.csv (text/csv) to [base]
POSTing file books.json (application/json) to [base]/json/docs
POSTing file gb18030-example.xml (application/xml) to [base]
POSTing file hd.xml (application/xml) to [base]
POSTing file ipod_other.xml (application/xml) to [base]
POSTing file ipod_video.xml (application/xml) to [base]
POSTing file manufacturers.xml (application/xml) to [base]
POSTing file mem.xml (application/xml) to [base]
POSTing file money.xml (application/xml) to [base]
POSTing file monitor.xml (application/xml) to [base]
POSTing file monitor2.xml (application/xml) to [base]
POSTing file more_books.jsonl (application/json) to [base]/json/docs
POSTing file mp500.xml (application/xml) to [base]
POSTing file post.jar (application/octet-stream) to [base]/extract
POSTing file sample.html (text/html) to [base]/extract
POSTing file sd500.xml (application/xml) to [base]
POSTing file solr-word.pdf (application/pdf) to [base]/extract
POSTing file solr.xml (application/xml) to [base]
POSTing file test_utf8.sh (application/octet-stream) to [base]/extract
POSTing file utf8-example.xml (application/xml) to [base]
POSTing file vidcard.xml (application/xml) to [base]
21 files indexed.
COMMITting Solr index changes to http://localhost:8983/solr/techproducts/update...
Time spent: 0:00:02.284
2.示例练习:
1).使用curl访问
curl “http://localhost:8983/solr/techproducts/select?q=foundation”
返回4条数据
2).使用curl访问
curl “http://localhost:8983/solr/techproducts/select?q=foundation&fl=id”
返回搜索id列表
{
"responseHeader":{
"zkConnected":true,
"status":0,
"QTime":6,
"params":{
"q":"foundation",
"fl":"id"}},
"response":{"numFound":4,"start":0,"maxScore":2.8034868,"docs":[
{
"id":"0553293354"},
{
"id":"UTF8TEST"},
{
"id":"SOLR1000"},
{
"id":"E:\\Solr\\solr-7.3.1\\example\\exampledocs\\test_utf8.sh"}]
}
}
3).使用web界面在.输入electronics
返回14条数据
4).使用web界面在.输入cat:electronics
返回12条数据
5).使用curl搜索短语CAS+latency
curl “http://localhost:8983/solr/techproducts/select?q=\”CAS+latency\”“
搜索2条数据
3.搭建报错
SimplePostTool: WARNING: IOException while reading response: java.io.FileNotFoundException: http://localhost:8983/solr/techproducts/update
POSTing file books.json (application/json) to [base]/json/docs
SimplePostTool: WARNING: Solr returned an error #404 (Not Found) for url: http://localhost:8983/solr/techproducts/update/json/docs
SimplePostTool: WARNING: Response: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /solr/techproducts/update/json/docs. Reason:
<pre> Not Found</pre></p>
</body>
解决方式: collection名字、configuration配置文件选错导致的,正确输入方式。
Please provide a name for your new collection: [gettingstarted]
techproducts
How many shards would you like to split techproducts into? [2]
How many replicas per shard would you like to create? [2]
Please choose a configuration for the techproducts collection, available options are:
_default or sample_techproducts_configs [_default]
sample_techproducts_configs
solrcloud常用命令
1.启动
E:\Solr\solr-7.3.1>.\bin\solr.cmd start -c -p 8983 -s example\cloud\node1\solr
Waiting up to 30 to see Solr running on port 8983
Started Solr server on port 8983. Happy searching!
E:\Solr\solr-7.3.1>.\bin\solr.cmd start -c -p 7574 -s example\cloud\node2\solr -z localhost:9983
Waiting up to 30 to see Solr running on port 7574
Started Solr server on port 7574. Happy searching!
2.删除集合
E:\Solr\solr-7.3.1\bin>solr.cmd delete -c techproducts
3.创建新的集合
bin/solr create -c -s 2 -rf 2
4.关闭服务
E:\Solr\solr-7.3.1>.\bin\solr.cmd stop -all
5.查看状态
E:\Solr\solr-7.3.1>.\bin\solr.cmd status
Found Solr process 1132 running on port 8983
{
"solr_home":"E:\\Solr\\solr-7.3.1\\server\\solr",
"version":"7.3.1 ae0705edb59eaa567fe13ed3a222fdadc7153680 - caomanhdat - 2018-05-09 09:30:57",
"startTime":"2018-07-21T10:25:55.177Z",
"uptime":"0 days, 0 hours, 2 minutes, 11 seconds",
"memory":"76.7 MB (%15.6) of 490.7 MB"}
6.查看版本
E:\Solr\solr-7.3.1>.\bin\solr.cmd version
7.3.1
7.使用curl访问
curl “http://localhost:8983/solr/techproducts/select?q=foundation&fl=id”
返回搜索id列表
{
"responseHeader":{
"zkConnected":true,
"status":0,
"QTime":6,
"params":{
"q":"foundation",
"fl":"id"}},
"response":{"numFound":4,"start":0,"maxScore":2.8034868,"docs":[
{
"id":"0553293354"},
{
"id":"UTF8TEST"},
{
"id":"SOLR1000"},
{
"id":"E:\\Solr\\solr-7.3.1\\example\\exampledocs\\test_utf8.sh"}]
}
}