Solr入門(一)

Solr入門

本文目標:瞭解,安裝,使用

學習資料:

https://lucene.apache.org/solr/resources.html

https://lucene.apache.org/solr/guide/7_6/solr-tutorial.html

 

什麼是Solr?

Solr is the popular, blazing-fast, open source enterprise search platform built on Apache Lucene.

Solr is highly reliable, scalable and fault tolerant, providing distributed indexing, replication and load-balanced querying, automated failover and recovery, centralized configuration and more. Solr powers the search and navigation features of many of the world's largest internet sites.

 我做實驗下載的是7.6.0版本,官網下載的。

啓動和配置solr集羣

以SolrCloud模式啓動:./solr.cmd start -e cloud

出現了第一個交互式回話問題:要在本地集羣啓動幾個節點?默認是2。

然後默認會使用兩個端口創建節點,並且創建Solr home目錄。

啓動了第一個節點。

然後啓動另一個節點,從日誌裏看到Zookeeper的信息,Solr Cloud模式默認使用ZK做Solr節點服務的註冊,發現,協調。

給collection起名

看來不需要一個個解釋每一步,很傻。跟着官方文檔來就好了,一步一步寫解釋速度太慢,後面不這樣寫了。

創建好的數據集,有兩個分片,這兩個分片在每個節點上都有,分片按索引分的,索引兩個分片的數據構成一個數據整體。

邏輯上每個分片有兩個副本,實際在不同節點上存儲。(具體見下面Gragh(Radial)展開的圖更清晰)

訪問http://localhost:8983/solr

選中側邊欄Gragh(Radial)能清楚的看到Solr存儲的網絡結構(理解這幅圖很重要):

下面這幅圖,顯示了分片的索引範圍和所在的節點:

小結:

通過上面的步驟,使用solr cloud模式創建了兩個node,一個數據集,每個node有一個shard,每個shard有兩個replica。

shard的作用是索引分片,舉個例子,將0-499的索引分到一個節點,將500到999的索引分到另一個節點。

replica是索引的副本,每個shard有兩個副本,目的是爲了故障恢復。

 

導入模擬數據

搜索

實驗1:查詢所有數據

實驗2:查詢關鍵詞爲foundation的數據

實驗3:在實驗2的基礎上只查詢屬性id

有一個小問題,發現我導的模擬數據和官網文檔不一樣。查詢的結果不一樣。

然後後面直接記錄下例子中的查詢姿勢吧:

http://localhost:8983/solr/techproducts/select?q=cat:electronics

查詢cat關鍵字和electronics關鍵字關聯的數據

http://localhost:8983/solr/techproducts/select?q=\"CAS+latency\"

查詢一個由兩個關鍵字組成的短語或者詞組。因爲英文分詞可以按空格分詞,但是現在這個需求就是想查CAS latency這個詞也是可以的。

http://localhost:8983/solr/techproducts/select?q=+electronics%20-music

使用+-進行組合查詢,表示包含不包含

更多關於搜索的,點擊這裏

收尾:

use the bin/solr script we started out with to delete this collection:

bin/solr delete -c techproducts

And then create a new collection:

bin/solr create -c <yourCollection> -s 2 -rf 2

To stop both of the Solr nodes we started, issue the command:

bin/solr stop -all

For more information on start/stop and collection options with bin/solr, see Solr Control Script Reference.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章