目前最新版的Solr是7.1.0
有個我還不清楚的地方是,為何5.5.X或者6.6.X版本還在更新,給我的感覺好像每一個大版本都有自己的維護團隊。不管了。
首先-系統要求
JDK1.8+
解壓Solr
~$ unzip -q solr-7.1.0.zip ~$ cd solr-7.1.0/
以SolrCloud模式啟動
Unix或MacOS:bin/solr start -e cloud
Windows:bin\solr.cmd start -e cloud
進入目錄-啟動【Linux僅僅命令不同】
D:\>cd solr-7.1.0 D:\solr-7.1.0>bin\solr.cmd start -e cloud Welcome to the SolrCloud example! 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? (spec ify 1-4 nodes) [2]:
這個時候直接回車Enter
Ok, let's start up 2 Solr nodes for your example SolrCloud cluster. Please enter the port for node1 [8983]:
再Enter
Please enter the port for node2 [7574]:
Enter,后面直接出現這么一大段
Creating Solr home directory D:\solr-7.1.0\example\cloud\node1\solr Cloning D:\solr-7.1.0\example\cloud\node1 into D:\solr-7.1.0\example\cloud\node2 Starting up Solr on port 8983 using command: "D:\solr-7.1.0\bin\solr.cmd" start -cloud -p 8983 -s "D:\solr-7.1.0\example\clou d\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: "D:\solr-7.1.0\bin\solr.cmd" start -cloud -p 7574 -s "D:\solr-7.1.0\example\clou d\node2\solr" -z localhost:9983 Waiting up to 30 to see Solr running on port 7574 INFO - 2017-11-03 09:37:54.245; org.apache.solr.client.solrj.impl.ZkClientClust erStateProvider; 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] Started Solr server on port 7574. Happy searching!
最后一段話:系統提示你創建一個用於索引數據的集合。因為Solr提供一些樣本數據,我們不妨與教程一致,在控制台輸入techproducts 然后回車。
techproducts How many shards would you like to split techproducts into? [2]
然后會讓你輸入想分割到兩個節點上的碎片數量。這里默認為2,就是均勻分割到兩個節點上。【我們目前有兩個節點,所以2就是平均分。如果我們建立三個節點,那么想要平均分就要輸入3】。直接回車。
How many replicas per shard would you like to create? [2]
你想為每個碎片創建多少副本?【副本是用來故障切換的】這里默認2,回車
Please choose a configuration for the techproducts collection, available options are: _default or sample_techproducts_configs [_default]
這里讓我們選擇一個配置。在本地我也找到了這兩個目錄
Solr有兩個開箱即用的配置文件樣本集,稱為“configSet”。而索引集合必須有一個“ConfigSet”。它包括兩個主要配置文件:
大家注意 sample_techproducts_configs ,它包括了我們定義的索引集合名稱:techproducts。這個config包含了我們需要的示例數據。所以在控制台上輸入sample_techproducts_configs並回車【可能會慢一點,耐心】:
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 D:\solr-7.1.0>
最后來訪問:
http://localhost:8983/solr
Solr現在將運行兩個“節點”,一個在端口7574上,一個在端口8983上。一個集合techproducts
,兩個分片集合,每個都有兩個副本。【點擊Cloud可見】
到此Solr已經啟動啦,可是還沒有數據。下面來完成
加入數據
Linux:solr-7.1.0:$ bin/post -c techproducts example/exampledocs/* Windows:D:\solr-7.1.0> java -jar -Dc=techproducts -Dauto example\exampledocs\post.jar example\exampledocs\*
結果:
D:\solr-7.1.0>java -jar -Dc=techproducts -Dauto example\exampledocs\post.jar exa mple\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:06.768 D:\solr-7.1.0>
基本搜索
訪問:http://localhost:8983/solr/#/techproducts/query
點擊Execute Query。開始查詢,你會發現右邊有好幾條JSON數據。准確來說:是十條
右上角是發送的URL,你可以點擊它,點擊試試看
查詢參數解釋:
修改q為foundation,結果顯示有四個命中。
將id放入fl中,再次查詢,你會發現顯示的字段只有id
我們再改變p為electronics,有14個結果。
這種查詢是在所有索引字段查詢包括electronics字段的文檔,如果想更精確一點,我們看到有一個cat字段,那么將p改為cat:electronics,意思為僅僅cat字段中包含electronics信息的數據。
可以看到,只有12條數據,更加精確了。
下面進行短語搜索
p改為"multiple terms here",短語搜索必需加上雙引號。
最后
如果你希望刪除此集合
D:\solr-7.1.0> bin\solr delete -c techproducts
注意:Linux的路徑為/
停止啟動的Solr
D:\solr-7.1.0> bin\solr stop -all