【问题标题】:How to ignore some fields in river mongodb and elasticsearch?如何忽略river mongodb和elasticsearch中的一些字段?
【发布时间】:2015-04-23 15:19:28
【问题描述】:

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

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

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

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢。如果有像 (a,b,c) 这样的 serval 字段,则使用 "exclude_fields": "a,b,c" 或 "exclude_fields": ["a","b","c"],哪个正确?
    • 列表就是你的答案:ES River MongoDB example
    【解决方案2】:

    我从 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"
        }
    }'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-06
      • 2023-02-25
      • 2012-02-26
      • 2014-09-09
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      相关资源
      最近更新 更多