Elasticsearch 参考指南(Reindex API)
Reindex API
重新索引要求为源索引中的所有文档启用_source。重新索引不会尝试设置目标索引,它不会复制源索引的设置,你应该在运行_reindex操作之前设置目标索引,包括设置映射、碎片数、副本等。_reindex的最基本形式只是将文档从一个索引复制到另一个索引,这会将twitter索引中的文档复制到new_twitter索引中:
POST _reindex
{
"source": {
"index": "twitter"
},
"dest": {
"index": "new_twitter"
}
}这将返回如下内容:
{
"took" : 147,
"timed_out": false,
"created": 120,
"updated": 0,
"deleted": 0,
"batches": 1,
"version_conflicts": 0,
"noops": 0,
"retries": {
"bulk": 0,
"search": 0
},
"throttled_millis": 0,
"requests_per_second": -1.0,
"throttled_until_millis": 0,
"total": 120,
"failures" : [ ]
}就像_update_by_query一样,_reindex获取源索引的快照,但其目标必须是不同的索引,因此版本冲突不太可能,dest元素可以像索引API一样配置,以控制乐观并发控制。只是省略version_type(如上所述)或将其设置为internal将导致Elasticsearch盲目地将文档转储到目标中,覆盖任何碰巧具有相同类型和id的文档:
POST _reindex
{
"source": {
"index": "twitter"
},
"dest": {
"index": "new_twitter",
"version_type": "internal"
}
}将version_type设置为external将导致Elasticsearch保留源中的version,创建缺少的任何文档,并更新目标索引中具有旧版本的文档而不是源索引中的任何文档:
POST _reindex
{
"source": {
"index": "twitter"
},
"dest": {
"index": "new_twitter",
"version_type": "external"
}
}设置op_type为create将导致_reindex仅在目标索引中创建缺少的文档,所有现有文档都会导致版本冲突:
POST _reindex
{
"source": {
"index": "twitter"
},
"dest": {
"index": "new_twitter",
"op_type": "create"
}
}默认情况下,版本冲突会中止_reindex进程,但你可以在请求体中设置"conflicts": "proceed"即可计算:
POST _reindex
{
"conflicts": "proceed",
"source": {
"index": "twitter"
},
"dest": {
"index": "new_twitter",
"op_type": "create"
}
}你可以通过向source添加类型或添加查询来限制文档,这个只会将kimchy写的推文复制到new_twitter中:
POST _reindex
{
"source": {
"index": "twitter",
"type": "_doc",
"query": {
"term": {
"user": "kimchy"
}
}
},
"dest": {
"index": "new_twitter"
}
} 相关推荐
newbornzhao 2020-09-14
做对一件事很重要 2020-09-07
renjinlong 2020-09-03
明瞳 2020-08-19
李玉志 2020-08-19
mengyue 2020-08-07
molong0 2020-08-06
AFei00 2020-08-03
molong0 2020-08-03
wenwentana 2020-08-03
YYDU 2020-08-03
另外一部分,则需要先做聚类、分类处理,将聚合出的分类结果存入ES集群的聚类索引中。数据处理层的聚合结果存入ES中的指定索引,同时将每个聚合主题相关的数据存入每个document下面的某个field下。
sifeimeng 2020-08-03
心丨悦 2020-08-03
liangwenrong 2020-07-31
sifeimeng 2020-08-01
mengyue 2020-07-30
tigercn 2020-07-29
IceStreamLab 2020-07-29