`

Solr: Solr Integrate with MongoDB

 
阅读更多

Install Mongo-Connector

pip install mongo-connector

pip uninstall mongo-connector

 

 

git clone https://github.com/10gen-labs/mongo-connector.git
cd mongo-connector
python setup.py install

 

modify doc_managers/solr_doc_manager.py

from mongo_connector import errors
#from mongo_connector.constants import (DEFAULT_COMMIT_INTERVAL,DEFAULT_MAX_BULK)
from constants import (DEFAULT_COMMIT_INTERVAL,DEFAULT_MAX_BULK)
from mongo_connector.util import retry_until_ok
#from mongo_connector.doc_managers import DocManagerBase, exception_wrapper
from doc_managers import DocManagerBase, exception_wrapper
#from mongo_connector.doc_managers.formatters import DocumentFlattener
from doc_managers.formatters import DocumentFlattener

 

 

Test

#mongo-connector


MongoDB Replica set

1. make the following dirs arch

rs
├── db
│   ├── rs1
│   │   ├── journal
│   │   └── _tmp
│   └── rs2
│       └── journal
└── log

2.  run two instances

#cd rs

#mongod --port 27001 --oplogSize 100 --dbpath db/rs1 --logpath log/rs1.log --replSet rs/127.0.0.1:27002 --journal 

#mongod --port 27002 --oplogSize 100 --dbpath db/rs2 --logpath log/rs2.log --replSet rs/127.0.0.1:27001 --journal

 

3. config replica set

#mongo --port 27001

>config={_id:'rs', members:[{_id:0, host:'localhost:27001'},{_id:1, host:'localhost:27002'}]}

>rs.initiate(config)

>rs.status()

rs:PRIMARY>

 

Dump data from mongo to solr

#python connector.py --unique-key=id --auto-commit-interval=0 -n test.test  -m localhost:27001 -t http://localhost:8983/solr/inokqreply -d solr_doc_manager.py

 

or

#mongo-connector   --auto-commit-interval=0 -n test.test  -m localhost:27001 -t http://localhost:8983/solr/inokqreply -d doc_managers/solr_doc_manager.py

 

------------------------------------------------------------------------------------------------------------------------------------

 

error:

 



 

 

 

modify python2.7/site-packages pysolr.py

    716             for bit in values:
    717                 if self._is_null_value(bit):
    718                     continue
    719 
    720                 #attrs = {'name': key}
    721                 attrs = {str('name'): key}
    722 
    723                 if boost and key in boost:
    724                     #attrs['boost'] = force_unicode(boost[key])
    725                     attrs[str('boost')] = force_unicode(boost[key])
    726 
    727                 field = ET.Element('field', **attrs)
    728                 field.text = self._from_python(bit)
    729 
    730                 doc_elem.append(field)

 

see related error :https://github.com/toastdriven/pysolr/issues/72

 

 error:

solution: delete the config.txt file under the dir which lanched the above command.

 

error:

  File "build/bdist.linux-x86_64/egg/pysolr.py", line 318, in _send_request
    error_message = self._extract_error(resp)
  File "build/bdist.linux-x86_64/egg/pysolr.py", line 397, in _extract_error
    reason, full_html = self._scrape_response(resp.headers, resp.content)
  File "build/bdist.linux-x86_64/egg/pysolr.py", line 418, in _scrape_response
    import lxml.html
ImportError: No module named lxml.html
2014-07-31 14:29:51,872 - ERROR - OplogThread: Failed during dump collection cannot recover! Collection(Database(MongoClient([u'localhost:27017', u'localhost:27018']), u'local'), u'oplog.rs')

Solution:

yum install python-lxml

yum install libxml2-python

yum install libxml2-dev or libxslt-devel

pip install lxml   or  pip install lxml==3.2.4

pip install cssselect

#ln -s /usr/local/python27/lib/libpython2.7.so /usr/local/lib/
 

 error

File "build/bdist.linux-x86_64/egg/pysolr.py", line 318, in _send_request
    error_message = self._extract_error(resp)
  File "build/bdist.linux-x86_64/egg/pysolr.py", line 397, in _extract_error
    reason, full_html = self._scrape_response(resp.headers, resp.content)
  File "build/bdist.linux-x86_64/egg/pysolr.py", line 429, in _scrape_response
    p_nodes = body_node.cssselect('p')
AttributeError: 'NoneType' object has no attribute 'cssselect'
2014-07-31 17:29:25,320 - ERROR - OplogThread: Failed during dump collection cannot recover! Collection(Database(MongoClient([u'localhost:27017', u'localhost:27018']), u'local'), u'oplog.rs')

Solution

https://github.com/toastdriven/pysolr/pull/92

 https://github.com/toastdriven/pysolr/pull/92

 https://github.com/toastdriven/pysolr/pull/92

 ==========================================================

pysolr

 

https://pypi.python.org/pypi/pysolr/3.2.0

 

===============================================================================

datetime

my situation is that there is a 'created_at' filed which store unix timestamp with long format

 

when import these data to solr by mongo-connect, there is a error "Invalide date string "

Solution:

1. uninstall mongo-connector

#pip uninstall mongo-connector

2. modify mongo_connector/doc_managers/formatters.py

    143     def transform_element(self, key, value):
    144         if isinstance(value, list):
    145             for li, lv in enumerate(value):
    146                 for inner_k, inner_v in self.transform_element(
    147                         "%s.%s" % (key, li), lv):
    148                     yield inner_k, inner_v
    149         elif isinstance(value, dict):
    150             formatted = self.format_document(value)
    151             for doc_key in formatted:
    152                 yield "%s.%s" % (key, doc_key), formatted[doc_key]
    153         else:
    154             # We assume that transform_value will return a 'flat' value,
    155             # not a list or dict
    156             # print("+++++++++++++++++++++ key=%s  value=%s" %(key,value))
    157             if key == "created_at":
    158                 yield key, self.transform_dateformat(value)
    159             else:
    160                 yield key, self.transform_value(value)

 

    105     def transform_dateformat(self, value):
    106         return datetime.datetime.fromtimestamp(int(value), None)

 

3. reinstall

#python setup.py install

 

Everything is OK.

 

 

http://tool.chinaz.com/Tools/unixtime.aspx

http://developwithstyle.com/articles/2010/07/09/handling-dates-in-mongodb/

https://wiki.python.org/moin/TimeTransitionsImage

 

 

 

===================================================================================

There is a post who support another mongodb-solr-DIH tool

http://stackoverflow.com/questions/9345335/solr-data-import-handlers-for-mongodb

#git clone https://github.com/james75/SolrMongoImporter

 

 

 -------------------------

init script

https://gist.github.com/lovett89/9260081

http://www.snip2code.com/Snippet/33459/mongo-connector-init-script-%28tested-on-C

https://github.com/10gen-labs/mongo-connector/issues/96

  1. Modify the variables at the top of mongo-connector.start to your liking
  2. Modify the wrapper variable at the top of the init script to point to the location of mongo-connector.start
  3. Place the mongo-connector script in /etc/init.d and run chkconfig --add mongo-connector

When I run chkconfig --add mongo-connector, there is no chkconfig command.

Solution:

sudo apt-get install sysv-rc-conf

 

 

=================================================================================

mongodb commands

http://blog.csdn.net/wangpeng047/article/details/7705588

 

 

References

http://www.cnblogs.com/sysuys/p/3403670.html

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

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

  • 大小: 151.3 KB
  • 大小: 71.5 KB
分享到:
评论

相关推荐

    mongodb-solr

    MongoDB和Solr是两种非常重要的开源搜索引擎与数据库系统,它们在大数据管理和搜索领域有着广泛的应用。MongoDB是一个文档型数据库,以灵活的数据模型、高可用性和可扩展性著称,而Solr则是Apache基金会的一个搜索...

    node-solr:Node.js 的 Solr 模块

    Node.js 的 Solr 模块参考Node.js: : Solr: : 使用npm test运行测试。 如果您没有在 127.0.0.1:8983 上运行 Solr,请编辑“test/common.js”。使用示例请参阅使用测试。 这是一个快速示例: var solr = require ( ...

    puppet-ispconfig_solr:在 IspConfig 环境中使用的 solr 包装器

    == 定义:ispconfig_solr::instance 这个定义是 solr::instance 的包装器。 它创建一个 solr 实例并配置它以在 IspConfig 环境中使用 == 参数: [ instance_name ] solr 实例的名称。 实例将被称为 solr-$...

    docker-solr:用于Solr的Docker构建,用于管理官方Docker Hub solr映像

    什么是Apache Solr:trade_mark:? Apache Solr具有高度的可靠性,可扩展性和容错性,可提供分布式索引,复制和负载平衡查询,自动故障转移和恢复,集中式配置等。 Solr为许多世界上最大的互联网站点提供搜索和导航...

    solr:Allegro Common Lisp与Solr的接口

    这是Allegro CL的Solr绑定。 Solr是来自Apache Lucene项目的开源自由文本索引/搜索平台。 有关详细信息,请参见以下URL。 该软件包允许Allegro CL应用程序与正在运行的Solr服务器通信,添加和删除文档以及运行查询以...

    lucene-solr:Apache Lucene和Solr开源搜索软件

    Solr: : 用Gradle构建 建筑Lucene 参见 。 建筑太阳能 首先,您需要设置开发环境(OpenJDK 11或更高版本)。 我们假设您知道如何获取和设置JDK-如果您不了解,那么我们建议您从开始并进一步了解

    solr -8.11.1.zip 文件

    solr -8.11.1.zip 文件

    docker-compose 构建以solr8.11.1为基础的含中文分词器的镜像

    以solr8.11.1为基础镜像,使用docker-compose构建含中文分词器的新的镜像 文件夹内含有docker-compose.yml脚本、Dockerfile脚本以及构建镜像所需中文分词器ik-analyzer-8.5.0.jar、所有扩展词和停用词相关的配置文件...

    mod_search_solr:用于 Solr 支持的 Zotonic 模块

    它内置了 Solr:只需安装此模块即可。 设置完成后,Zotonic 会将其保存的每个资源推送到 Solr,以便可以查询数据库。 要将整个站点重新索引到 Solr,请按管理员中的“重建搜索索引”按钮。 安装 您需要为每个要为...

    solr笔记solr笔记

    2. 解压 Solr:解压 Solr 的安装包,包括 Bin、Contrib、Dist、Docs、Example、Solr、Multicore、Webapps、Licenses 等目录。 3. 安装 SolrCore:SolrCore 是 Solr 的核心组件,需要安装和配置 SolrCore。 4. 配置 ...

    mir-solr:MIR SOLR配置

    "mir-solr:MIR SOLR配置"是一个与Solr相关的项目,可能涉及到在MIR(可能是某种特定的系统或框架)中集成和配置Apache Solr的细节。Apache Solr是一个开源的全文搜索引擎,常用于大数据量、高性能的搜索应用。在MIR...

    java8看不到源码-ansible-role-solr:yauh.solr-用于设置Solr的Ansible角色

    看不到源码Solr 引导程序 设置 Solr 搜索平台的 Ansible 角色 要求 系统上需要有Java,推荐角色yauh.java8。 角色变量 以下变量可与 solr 角色一起使用: solr_source: http://apache.openmirror.de/lucene/solr # ...

    solr5.4.0完整包

    Solr 依存于Lucene,因为Solr底层的核心技术是使用Lucene 来实现的,Solr和Lucene的本质区别有以下三点:搜索服务器,企业级和管理。...所以说,一句话概括 Solr: Solr是Lucene面向企业搜索应用的扩展。

    nodebb-plugin-solr:使用Apache Solr全文搜索NodeBB

    Solr搜索NodeBB : Solr(发音为“ solar”)是来自Apache Lucene项目的开源企业搜索平台。 它的主要功能包括全文搜索,命中突出显示,多面搜索,动态聚类,数据库集成以及丰富的文档(例如Word,PDF)处理。 此...

    Laravel-4-Solr:Apache Solr简单查询客户端

    Laravel 4 Apache Solr Laravel 4软件包提供了一个接口,用于通过其静态接口使用(查询) 。安装首先通过Composer安装此软件包。 编辑项目的composer.json文件,以要求davispeixoto/laravel-4-solr 。 "require": {...

    Solr:将solr与spring boot一起使用

    Spring Boot和Solr 在这个示例中,我们看到如何将spring boot与solr一起用作数据库: Sprint Boot平板电脑索尔我们要做的第一件事是在solr de vehicle中创建模式以保存车辆的信息。 使用此命令,我们将使用bash脚本...

    data_solr:CreateIndexBySolr

    本项目"**data_solr:CreateIndexBySolr**"聚焦于如何使用Solr的Java客户端库SolrJ来创建索引,并进行搜索操作。我们将深入探讨这个过程中的关键概念和技术细节。 首先,让我们了解**Solr**的基本概念。Solr是基于...

    cl-solr:用于 Common Lisp 的 Apache Solr API

    "cl-solr:用于 Common Lisp 的 Apache Solr API" 这个标题揭示了我们讨论的主题是一个名为 "cl-solr" 的软件库,它为 Common Lisp 编程语言提供了与 Apache Solr 的接口。Apache Solr 是一个流行的开源搜索引擎,...

    spring-data-solr:通过spring对solr数据的增删该查,进行封装

    **Spring Data Solr:通过Spring对Solr数据的增删改查封装** Spring Data Solr是Spring Data项目的一部分,它为Apache Solr搜索引擎提供了一种简单而强大的集成方式。Spring Data Solr允许开发者利用Spring框架的...

    solr:Apache Solr开源搜索软件

    阿帕奇·索尔(Apache Solr) Apache Solr是一个用Java编写并使用的企业搜索平台。 主要功能包括全文搜索,索引复制和分片以及结果分面和突出显示。在线文件此自述文件仅包含基本的安装说明。 有关更全面的文档,请...

Global site tag (gtag.js) - Google Analytics