【发布时间】:2018-03-03 01:47:31
【问题描述】:
我目前正在做一个项目,我们的主数据库是 mongodb,我们使用 elasticsearch 进行搜索。我们已经通过 java 应用程序将数据插入到 mongodb 中。我们使用 River 插件来同步数据。到目前为止,我们已经通过执行下面提到的 shellscript 文件手动完成了 mongodb 和 elasticsearch 之间的数据同步。 (setup.sh && bash.sh)
//setup.sh
curl -XPOST http://localhost:9200/classdata -d @setup.json
//setup.json
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"classdata": {
"properties": {
"className": {
"type": "string"
},
"jarID": {
"index": "not_analyzed",
"type": "string"
},
"jarFileName": {
"index": "not_analyzed",
"type": "string"
},
"dependencies": {
"properties": {
"methodSignature": {
"type": "string"
},
"dependedntClass": {
"type": "string"
}
}
}
}
}
}
}
//bash.sh
curl -XPUT "localhost:9200/_river/classdata/_meta" -d '
{
"type": "mongodb",
"mongodb": {
"servers": [
{ "host": "127.0.0.1", "port": 27017 }
],
"options": { "secondary_read_preference": true },
"db": "E",
"collection": "ClassData"
},
"index": {
"name": "classdata",
"type": "classdata"
}
}'
但现在我们的要求发生了变化。现在我们需要自动化这个过程,比如在将数据插入到 mongodb 之后,我们必须在 elasticsearch 和 mongodb 之间自动同步数据。 我不知道该怎么做。如果有人知道如何自动化这个过程,请帮助我。
【问题讨论】:
-
在将数据插入 mongodb 后,为什么不创建一个方法从 java 程序中执行那些 sh 文件?
-
这不可能我猜每个操作系统都不支持执行shellscript文件吧?
标签: java mongodb elasticsearch