[英]How to do custom mapping using mongo connector with elasticsearch
I wanna connect mongodb and elasticsearch . 我想连接mongodb和elasticsearch 。 I used mongo connector to connect them. 我用mongo连接器连接它们。 I followed instruction from below link to setup==> 我按照下面的说明从链接到setup ==>
http://vi3k6i5.blogspot.in/2014/12/using-elastic-search-with-mongodb.html http://vi3k6i5.blogspot.in/2014/12/using-elastic-search-with-mongodb.html
I am able to connect mongodb and elasticsearch. 我能够连接mongodb和elasticsearch。 But by default mongo connector created indices in elasticsearch for all databases of mongodb. 但是默认情况下,mongo连接器在elasticsearch中为mongodb的所有数据库创建了索引。
I want to create only one index for my one database and I want to insert only selected field of documents. 我只想为我的一个数据库创建一个索引,并且只想插入文档的选定字段。 for example: in mongo shell==> 例如:在mongo shell ==>
use hotels
db.restaurants.insert(
{
"address" : {
"street" : "2 Avenue",
"zipcode" : "10075",
"building" : "1480",
"coord" : [ -73.9557413, 40.7720266 ],
},
"borough" : "Manhattan",
"cuisine" : "Italian",
"grades" : [
{
"date" : ISODate("2014-10-01T00:00:00Z"),
"grade" : "A",
"score" : 11
},
{
"date" : ISODate("2014-01-16T00:00:00Z"),
"grade" : "B",
"score" : 17
}
],
"name" : "Vella",
"restaurant_id" : "41704620"
}
)
This will create database hotels and collection restaurants . 这将创建数据库酒店和收藏餐厅 。 Now I want to create index and I want to put only address field in elasticsearch for that index. 现在,我想创建索引,并且只想在该索引的弹性搜索中放入地址字段 。
Below are the steps what I tried but thats not working : First I start mongo connector like below : 下面是我尝试的步骤,但是那是行不通的:首先,我启动mongo连接器,如下所示:
Imomadmins-MacBook-Pro:~ jayant$ mongo-connector -m localhost:27017 -t localhost:9200 -d elastic_doc_manager --oplog-ts oplogstatus.txt
Logging to mongo-connector.log.
Then from new shell tab, I made command like : 然后从新的shell选项卡中,我发出如下命令:
curl -XPUT 'http://localhost:9200/hotels.restaurants/'
curl -XPUT "http://localhost:9200/hotels.restaurants/string/_mapping" - d'{
"string": {
"properties" : {
"address" : {"type" : "string"}
}
}
}'
But only index is created in elasticsearch named as hotels.restaurants . 但是在弹性搜索中仅创建名为Hotels.restaurants的索引 。 I can't see any document for index hotels.restaurants . 我找不到索引hotel.restaurants的任何文档。
Please suggest me how to add document for hotels.restaurants 请建议我如何为hotel.restaurants添加文件
好了,我得到了我的问题的答案,在启动mongo连接器时,我们可以指定集合名称和我们感兴趣的字段列表。请检查以下命令==>
$ mongo-connector -m localhost:27017 -t localhost:9200 -d elastic_doc_manager --oplog-ts oplogstatus.txt --namespace-set hotels.restaurants --fields address,grades,name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.