Elasticsearch学习笔记(三) mongodb数据同步

来源:互联网 发布:c语言什么时候用flag 编辑:程序博客网 时间:2024/06/05 09:48

使用 elasticsearch-river-mongodb插件同步mongodb 数据。


1、安装 elasticsearch-river-mongodb


elasticsearch   bin目录下执行:


./elasticsearch-1.4.4/bin/plugin -i com.github.richardwilly98.elasticsearch/elasticsearch-river-mongodb/2.0.9(在线安装)
2、同步操作:
⑴创建索引:

curl -XPUT http://192.9.8.222:9200/reslib

⑵连接数据库

curl -XPUT http://192.9.8.222:9200/_river/mongodb_river/_meta -d '

{

    "type": "mongodb",

    "mongodb": {

        "servers": [

            {

                "host": "192.9.8.204",

                "port": "27017"

            }

        ],

        "db": "reslibdb",

        "collection": "libresource",

        "script": "if( ctx.document.resStatus !=\"AUDITPASS\") { ctx.deleted = true; }"

    },

    "index": {

        "name": "reslib",

        "type": "res"

    }

}'