[英]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: 跟着这些步骤:
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>
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.