Mongo-connector整合MongoDB到Solr實現增量索引

來源:互聯網
上載者:User

標籤:solr   mongodb   replset   mongo-connector   

Mongo-connector整合MongoDB到Solr實現增量索引

 

配置MongoDB複製集

參考:《部署一個用於測試和開發的複製集》


安裝Solr5.3

參考:《在CentOS下安裝Solr5.3》


安裝Python2.7

參考:《在CentOS下安裝Python2.7》


安裝pip

參考:《在CentOS下安裝pip》


安裝mongo-connector


方法一:使用pip安裝

pip install mongo-connector

安裝到了ython的預設包目錄下:

/usr/local/lib/python2.7/site-packages


方法二:安裝為服務

1. 去https://github.com/mongodb-labs/mongo-connector/archive/master.zip下載mongo-connector-master.zip。

2. 解壓縮進入目錄。

unzip mongo-connector-master.zipcd mongo-connector-master

3. 編輯設定檔。

vi config.json

4. 安裝為服務。

python setup.py install_service

在/etc/init.d下建立了mongo-connector服務,並拷貝config.json檔案到/etc/mongo-connector.json。


卸載mongo-connector服務

python setup.py uninstall_service

它將移除/etc/init.d/mongo-connector和/etc/mongo-connector.json


查看服務狀態

service mongo-connector status


配置Solr


在Solr資料目錄/data/solr/data/下有Solr設定檔solr.xml


建立core

su - solr -c "/usr/local/solr/solr/bin/solr create -c card -n data_driven_schema_configs"

產生了檔案夾/data/solr/data/card,在/data/solr/data/card/conf目錄下是card的配置目錄,可以配置同義字、停止詞。


配置solrconfig.xml

1. 確保啟用了LukeRequestHandler

以下行應用出現在solrconfig.xml檔案中。

<requestHandler name="/admin/luke" class="org.apache.solr.handler.admin.LukeRequestHandler" />

2. 配置硬提交(重新整理到硬碟上的頻率)和軟提交(提交到記憶體中的頻率)

在solrconfig.xml檔案中配置<autoCommit>和<autoSoftCommit>

<autoCommit><maxTime>300000</maxTime><maxDocs>10000</maxDocs><openSearcher>true</openSearcher></autoCommit><!-- softAutoCommit is like autoCommit except it causes a‘soft‘ commit which only ensures that changes are visiblebut does not ensure that data is synced to disk. This isfaster and more near-realtime friendly than a hard commit.--><autoSoftCommit><maxDocs>1000</maxDocs><maxTime>60000</maxTime></autoSoftCommit>


配置schema.xml

1. Mongo Connector儲存中繼資料在每個文檔中協助處理復原。為了支援這些資料,你需要添加如下資訊到你的schema.xml中:

<field name="_ts" type="long" indexed="true" stored="true" /><field name="ns" type="string" indexed="true" stored="true"/>

2. 在schema.xml中配置配置<uniqueKey>、<field>


啟動mongo-connector


方法一:以命令列啟動

nohup sudo mongo-connector -m localhost:27019 -t http://localhost:8983/solr/card -o oplog_progress.txt -n example.card -u _id -d solr_doc_manager > mongo-connector.out 2>&1


方法二:以服務啟動

service mongo-connector start


Solr刪除全部索引


http://192.168.11.52:8983/solr/card/update/?stream.body=%3Cdelete%3E%3Cquery%3E*:*%3C/query%3E%3C/delete%3E&stream.contentType=text/xml;charset=utf-8&commit=true


參考:

http://blog.mongodb.org/post/29127828146/introducing-mongo-connector

https://github.com/mongodb-labs/mongo-connector/wiki/Installation

https://github.com/mongodb-labs/mongo-connector/wiki/Usage-with-Solr

https://loutilities.wordpress.com/2012/11/26/complementing-mongodb-with-real-time-solr-search/



本文出自 “SQL Server Deep Dives” 部落格,請務必保留此出處http://ultrasql.blog.51cto.com/9591438/1696083

Mongo-connector整合MongoDB到Solr實現增量索引

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.