reindex
Reindex不会尝试设置目标索引。它不会复制源索引的设置。您应该在运行_reindex操作之前设置目标索引,包括设置映射,分片计数,副本等。
最基本的形式,_reindex只是将文档从一个索引复制到另一个索引.以下是将twitter索引的文档复制到new_twitter中
将twitter索引中的文档复制到new_twitter中.1
2
3
4
5
6
7
8
9
10curl -X POST "localhost:9200/_reindex" -H 'Content-Type: application/json' -d'
{
"source": {
"index": "twitter"
},
"dest": {
"index": "new_twitter"
}
}
'
将返回的结果如下1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19{
"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" : [ ]
}
_reindex 索取source索引的快照目标必须是不同的索引,避免发生版本冲突.
- version_type 设置为 internal 或 external
op_type 设置为create , 在开始设置 “conflicts”: “proceed”, 来避免冲突
1
2
3
4
5
6
7
8
9
10
11
12curl -X POST "localhost:9200/_reindex" -H 'Content-Type: application/json' -d'
{
"conflicts": "proceed",
"source": {
"index": "twitter"
},
"dest": {
"index": "new_twitter",
"op_type": "create"
}
}
'在source中添加,可以添加参数来限制文档.
type
可以是一个list,query
限制查询结果size
来限制文档的数量.sort
限制排序- 同时用
script
来修改文档的数据1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16curl -X POST "localhost:9200/_reindex" -H 'Content-Type: application/json' -d'
{
"source": {
"index": "twitter",
"type": "_doc",
"query": {
"term": {
"user": "kimchy"
}
}
},
"dest": {
"index": "new_twitter"
}
}
'
返回的参数说明
# | # |
---|---|
took | 整个操作所花费的总毫秒数。 |
timed_out | true如果在重新索引期间执行的任何请求超时 ,则将此标志设置为。 |
total | 已成功处理的文档数。 |
updated | 已成功更新的文档数。 |
created | 已成功创建的文档数。 |
deleted | 已成功删除的文档数。 |
batches | 重新索引拉回的滚动响应数。 |
noops | 由于用于reindex的脚本返回noop值而忽略的文档数ctx.op。 |
version_conflicts | 重新索引的版本冲突数。 |
retries | reindex尝试重试的次数。bulk是重试的批量操作search的数量,是重试的搜索操作的数量。 |
throttled_millis | 请求睡眠符合的毫秒数requests_per_second。 |
requests_per_second | 在reindex期间有效执行的每秒请求数。 |
throttled_until_millis | 该字段在_delete_by_query响应中应始终等于零。它只在使用Task API时有意义,它指示下一次(自纪元以来的毫秒数),为了符合,将再次执行受限制的请求requests_per_second。 |
failures | 如果在此过程中存在任何不可恢复的错误,则会出现故障数组。如果这是非空的,那么请求因为那些失败而中止。Reindex是使用批处理实现的,任何故障都会导致整个进程中止,但当前批处理中的所有故障都会被收集到数组中。您可以使用该conflicts选项来防止reindex在版本冲突中中止。 |
您可以使用Task API获取所有正在运行的reindex请求的状态 :
curl -X GET “localhost:9200/_tasks?detailed=true&actions=*reindex”