【问题标题】:Index the first 100 documents only from MongoDB to Elasticsearch仅将前 100 个文档从 MongoDB 索引到 Elasticsearch
【发布时间】:2015-04-11 08:25:37
【问题描述】:

我使用 elasticsearch 1.4.2 和 mongodb 2.6.6 以及用于 elasticsearch 的 River 插件,以从我的数据库中的集合中进行索引。但是,我只想索引前 100 个文档,而不是所有文档(超过 30,000 个) 我怎样才能做到这一点?这是我的索引:

curl -XPUT 'http://localhost:9200/_river/mongodb/_meta' -d '{
    "type": "mongodb", 
    "mongodb": { 
    "db": "mydb",
    "collection": "test"
    }, 
    "index": { 
      "name": "mongoindex",
      "type": "mongodb"
    }
}'

【问题讨论】:

  • 什么排序定义了“第一”?
  • @wdberkeley 没有具体顺序。我只想从文档中提取一个样本进行测试,而我没有足够的内存来存储所有文档。 100 份或更少的文件就足够了。所以即使结果是随机的,也没关系。

标签: mongodb indexing elasticsearch


【解决方案1】:

这是一个奇怪的用例,我不明白你为什么要这样做,但你可以在 MongoDB-River 中使用 custom filters。将过滤器设置为"{ "to_elastic_search" : true }",然后在 MongoDB 中使用该过滤器标记 100 个文档:

> db.test.find().limit(100).forEach(function(doc) {
    db.test.update({ "_id" : doc._id }, { "$set" : { "to_elastic_search" : true } }) 
} )

【讨论】:

  • 感谢您的回答。我这样做是为了测试。
猜你喜欢
  • 2017-07-15
  • 2016-03-02
  • 2012-04-07
  • 2020-01-24
  • 1970-01-01
  • 1970-01-01
  • 2021-02-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多