如何忽略 river mongodb 和 elasticsearch 中的某些字段?

How to ignore some fields in river mongodb and elasticsearch?

我使用 river mongo 将 mongodb 集合绑定到弹性搜索。

这导致 mongo 集合中的每个字段都将保存在 elasticseach 索引中。

我想知道如何忽略某些字段,不要让它保存在弹性索引中。

设置mongodb河流时,可以排除某些字段,例如

 "mongodb": {
        "db": "YourDbName",
        "collection": "YourCollectionName",
        "options": {
              "exclude_fields": "name_of_field_to_be_ignored"
            }
    },

我从 river mongo wiki 得到了另一种方法。通过使用脚本,您可以自定义..但是,您应该在 elasticsearch.yml 中将禁用脚本设置为 false。

https://github.com/richardwilly98/elasticsearch-river-mongodb/wiki

$ curl -XPUT "localhost:9200/_river/mongoscriptfilter/_meta" -d'
{
  "type": "mongodb",
    "mongodb": {
      "db": "testmongo", 
      "collection": "documents", 
      "script": "ctx.document.title = ctx.document.title_from_mongo; delete ctx.document.title_from_mongo;"
    },
    "index": {
      "name": "testmongo", 
      "type": "documents"
    }
}'