简体   繁体   English

使用ElasticSearch索引mongoDB

[英]Index mongoDB with ElasticSearch

I already have MongoDB and installed Elasticsearch with Mongoriver . 我已经拥有MongoDB并使用Mongoriver安装了Elasticsearch。 So I set up my river: 所以我建立了我的河流:

$ curl -X PUT localhost:9200/_river/database_test/_meta -d '{
  "type": "mongodb",
  "mongodb": {
    "servers": [
      {
        "host": "127.0.0.1",
        "port": 27017
      }
    ],
    "options": {
      "secondary_read_preference": true
    },
    "db": "database_test",
    "collection": "event"
  },
  "index": {
    "name": "database_test",
    "type": "event"
  }
}'

I simply want to get events that have country:Canada so I try: 我只是想得到有country:Canada事件country:Canada所以我尝试:

$ curl -XGET 'http://localhost:9200/database_test/_search?q=country:Canada'

And I get: 我得到:

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

I am searching the web and I read that I should first index my collection with Elasticsearch (lost the link). 我在网上搜索,我读到我应该首先用Elasticsearch索引我的收藏(丢失链接)。 Should I index my Mongodb? 我应该索引我的Mongodb吗? What should I do to get results from an existing MongoDB collection? 如何从现有的MongoDB集合中获取结果?

The mongodb river relies on the operations log of MongoDB to index documents, so it is a requirement that you create your mongo database as a replica set. mongodb河依赖于MongoDB的操作日志来索引文档,因此需要将mongo数据库创建为副本集。 I assume that you're missing it, so when you create the river, the initial import sees nothing to index. 我假设你错过了它,所以当你创建河流时,初始导入看不到索引。 I am also assuming that you're on Linux and you have a handle on the shell cli tools, so try this: 我也假设您使用的是Linux,并且掌握了shell cli工具,请尝试以下操作:

Follow these steps: 跟着这些步骤:

  • Make sure that the mapper-attachments Elasticsearch plugins is also installed 确保还安装了映射器附件Elasticsearch插件
  • Make a backup of your database with mongodump 使用mongodump备份数据库
  • edit mongodb.conf (usually in /etc/mongodb.conf, but varies on how you installed it) and add the line: 编辑mongodb.conf(通常在/etc/mongodb.conf中,但在安装方式上有所不同)并添加以下行:

    replSet = rs0

    "rs0" is the name of the replicaset, it can be whatever you like. “rs0”是复制品的名称,它可以是您喜欢的任何名称。

  • restart your mongo and then log in its console. 重启你的mongo然后登录它的控制台。 Type: 类型:

    rs.initiate()
    rs.slaveOk()

The prompt will change to rs0:PRIMARY> 提示符将更改为rs0:PRIMARY>

  • Now create your river just as you did in the question and restore your database with mongorestore. 现在就像在问题中一样创建你的河流,并使用mongorestore恢复你的数据库。 Elasticsearch should index your documents. Elasticsearch应该索引您的文档。

I recomend using this plugin: http://mobz.github.io/elasticsearch-head/ to navigate your indexes and rivers and make sure your data got indexed. 我建议使用这个插件: http//mobz.github.io/elasticsearch-head/来浏览你的索引和河流,并确保你的数据被索引。

If that doesnt work, please post which versions you are using for the mongodb-river-plugin, elasticsearch and mongodb. 如果这不起作用,请发布您用于mongodb-river-plugin,elasticsearch和mongodb的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 来自mongodb的ElasticSearch索引? - ElasticSearch index from mongodb? 未在 kibana 中为 mongodb + logstash +elasticsearch 创建索引 - Index not creating in kibana for mongodb + logstash +elasticsearch 如何使用Elasticsearch为MongoDB的“ id_”字段建立索引? - How to index the MongoDB “id_” field with Elasticsearch? 如何使用ElasticSearch,River和MongoDB创建索引? - How to create an index with ElasticSearch, River and MongoDB? 从mongodb仅对ElasticSearch中的某些字段编制索引 - Index only some fields in ElasticSearch from mongodb Nutch没有使用Mongodb正确地索引Elasticsearch - Nutch does not Index on Elasticsearch correctly using Mongodb 通过mongodb河在elasticsearch中创建索引的映射没有生效 - mapping in create index in elasticsearch through mongodb river is not taking effect 如何使用logstash将数组数据类型从mongodb索引到elasticsearch - How to index array data type from mongodb to elasticsearch using logstash 使用Node测试ElasticSearch。 填充MongoDB后强制更新索引 - Testing ElasticSearch with Node. Force update index after populating MongoDB 如何使用传输器为mongodb的特定数据库的特定集合建立索引(elasticsearch)? - How to index(elasticsearch) a specific collection of a specific db of mongodb using transporter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM