【发布时间】:2016-01-03 08:41:09
【问题描述】:
我想连接 mongodb 和 elasticsearch。我使用 mongo 连接器 来连接它们。我按照以下链接中的说明进行设置==>
http://vi3k6i5.blogspot.in/2014/12/using-elastic-search-with-mongodb.html
我可以连接 mongodb 和 elasticsearch。但默认情况下,mongo 连接器在弹性搜索中为 mongodb 的所有数据库创建索引。
我只想为我的一个数据库创建一个索引,并且我只想插入选定的文档字段。例如:在 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"
}
)
这将创建数据库酒店和收藏餐厅。现在我想创建索引,并且只想将 address field 放入 elasticsearch 中以获取该索引。
以下是我尝试过但不起作用的步骤: 首先,我启动 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.
然后从新的 shell 选项卡中,我发出如下命令:
curl -XPUT 'http://localhost:9200/hotels.restaurants/'
curl -XPUT "http://localhost:9200/hotels.restaurants/string/_mapping" - d'{
"string": {
"properties" : {
"address" : {"type" : "string"}
}
}
}'
但在名为 hotels.restaurants 的弹性搜索中只创建了索引。我看不到索引 hotels.restaurants 的任何文档。
请建议我如何为 hotels.restaurants
添加文档【问题讨论】:
标签: mongodb elasticsearch