在elasticsearch中重新索引时,“查询”中的“大小”没有影响

时间:2016-09-07 10:22:16

标签: elasticsearch logstash logstash-configuration

我一直在使用logstash将索引迁移到另一个索引。我最近尝试从本地环境中的大型数据集重新索引一定数量的数据。所以我尝试使用以下配置进行迁移:

input{
  elasticsearch{
    hosts=>"localhost:9200"
    index=>"old_indexindex"
    query=>'{"query":{"match_all":{}},"size":10 }'
  }
}filter{
  mutate{
    remove_field=>[
      "@version",
      "@timestamp"
    ]
  }
}output{
  elasticsearch{
    hosts=>"localhost:9200"
    index=>"new_index"
    document_type=>"contact"
    manage_template=>false
    document_id=>"%{contactId}"
  }
}

但是这会将 old_index 中的所有文档重新索引到 new_index ,其中,我希望只需 10 文档在new_index中重新编制索引。 我是否使用带有elasticsearch的logstash错过了一些概念?

1 个答案:

答案 0 :(得分:1)

elasticsearch输入不进行常规搜索,而是进行scan/scroll搜索类型。这意味着将从索引中检索所有数据,size参数的作用仅用于定义在每次滚动期间将获取多少数据,而不是将获取多少数据共

另请注意,查询本身中的size参数无效。您需要使用elasticsearch输入的size parameter,而不是在查询中指定它。

input{
  elasticsearch{
    hosts=> "localhost:9200"
    index=> "old_index"
    query=> '*'
    size => 10                 <--- size goes here
  }
}

话虽如此,如果您正在运行ES 2.3或更高版本,那么可以使用Reindex API实现您的目标,如下所示:

POST /_reindex
{
  "size": 10,
  "source": {
    "index": "old_index"
  },
  "dest": {
    "index": "new_index"
  }
}