最基本的形式_reindex只是將文檔從一個索引複製到另一個索引。如將gaoyh索引中的文檔複製到test索引中:
POST _reindex
{
"source": {
"index": "gaoyh"
},
"dest": {
"index": "test"
}
}
響應結果:
{
"took": 161,
"timed_out": false,
"total": 5,
"updated": 0,
"created": 5,
"deleted": 0,
"batches": 1,
"version_conflicts": 0,
"noops": 0,
"retries": {
"bulk": 0,
"search": 0
},
"throttled_millis": 0,
"requests_per_second": -1,
"throttled_until_millis": 0,
"failures": []
}
POST _reindex
{
"source": {
"index": "gaoyh"
},
"dest": {
"index": "test",
"version_type": "internal"
}
}
POST _reindex
{
"source": {
"index": "gaoyh"
},
"dest": {
"index": "index_test",
"version_type": "external"
}
}
{
"took": 33,
"timed_out": false,
"total": 5,
"updated": 0,
"created": 4,
"deleted": 0,
"batches": 1,
"version_conflicts": 1,
"noops": 0,
"retries": {
"bulk": 0,
"search": 0
},
"throttled_millis": 0,
"requests_per_second": -1,
"throttled_until_millis": 0,
"failures": [
{
"index": "index_test",
"type": "test",
"id": "1",
"cause": {
"type": "version_conflict_engine_exception",
"reason": "[test][1]: version conflict, current version [1] is higher or equal to the one provided [1]",
"index_uuid": "Qqk6nvQMQFGE6tw3Xb-PGw",
"shard": "0",
"index": "index_test"
},
"status": 409
}
]
}
{
"took": 4,
"timed_out": false,
"total": 5,
"updated": 5,
"created": 0,
"deleted": 0,
"batches": 1,
"version_conflicts": 0,
"noops": 0,
"retries": {
"bulk": 0,
"search": 0
},
"throttled_millis": 0,
"requests_per_second": -1,
"throttled_until_millis": 0,
"failures": []
}
POST _reindex
{
"source": {
"index": "gaoyh"
},
"dest": {
"index": "index_test",
"op_type": "create"
}
}
POST _reindex
{
"conflicts": "proceed",
"source": {
"index": "gaoyh"
},
"dest": {
"index": "index_test",
"op_type": "create"
}
}
POST _reindex
{
"source": {
"index": "twitter",
"type": "_doc",
"query": {
"term": {
"user": "kimchy"
}
}
},
"dest": {
"index": "new_twitter"
}
}
POST _reindex
{
"size": 2,
"source": {
"index": "gaoyh"
},
"dest": {
"index": "index_test"
}
}
POST _reindex
{
"source": {
"index": "twitter",
"_source": ["user", "_doc"]
},
"dest": {
"index": "new_twitter"
}
}
POST _bulk
{"index":{"_index":"gaoyh","_type":"test","_id":"1"}}
{"user":"aaa","content":"test"}
{"index":{"_index":"gaoyh","_type":"test","_id":"2"}}
{"user":"aaa","content":"test"}
{"index":{"_index":"gaoyh","_type":"test","_id":"3"}}
{"user":"ccc","content":"test"}
{"index":{"_index":"gaoyh","_type":"test","_id":"4"}}
{"user":"bbb","content":"test"}
{"index":{"_index":"gaoyh","_type":"test","_id":"5"}}
{"user":"bbb","content":"test"}
PUT index_test
{
"settings":{
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"test":{
"properties": {
"user":{
"type": "text"
},
"content":{
"type": "text"
}
}
}
}
}
POST _reindex
{
"source": {
"index": "gaoyh"
},
"dest": {
"index": "index_test",
"version_type": "external"
},
"script": {
"source":"if(ctx._source.user=='aaa'){ctx._version++;ctx._source.remove('user')}",
"lang": "painless"
}
}
GET index_test/test/_mget
{ "ids":["1","2","3","4","5"] }
響應結果如下:
{
"docs": [
{
"_index": "index_test",
"_type": "test",
"_id": "1",
"_version": 2,
"found": true,
"_source": {
"content": "test"
}
},
{
"_index": "index_test",
"_type": "test",
"_id": "2",
"_version": 2,
"found": true,
"_source": {
"content": "test"
}
},
{
"_index": "index_test",
"_type": "test",
"_id": "3",
"_version": 1,
"found": true,
"_source": {
"user": "ccc",
"content": "test"
}
},
{
"_index": "index_test",
"_type": "test",
"_id": "4",
"_version": 1,
"found": true,
"_source": {
"user": "bbb",
"content": "test"
}
},
{
"_index": "index_test",
"_type": "test",
"_id": "5",
"_version": 1,
"found": true,
"_source": {
"user": "bbb",
"content": "test"
}
}
]
}
- noop
- delete
- 其他
- keep
- discard
- =<some text>
POST _reindex
{
"source": {
"index": "source",
"query": {
"match": {
"company": "cat"
}
}
},
"dest": {
"index": "dest",
"routing": "=cat"
}
}
POST test/_doc/1?refresh
{
"text": "words words",
"flag": "foo"
}
POST _reindex
{
"source": {
"index": "test"
},
"dest": {
"index": "test2"
},
"script": {
"source": "ctx._source.tag = ctx._source.remove(\"flag\")"
}
}
GET test2/_doc/1
return:
{
"found": true,
"_id": "1",
"_index": "test2",
"_type": "_doc",
"_version": 1,
"_source": {
"text": "words words",
"tag": "foo"
}
}
POST _reindex
{
"source": {
"remote": {
"host": "http://otherhost:9200",
"username": "user",
"password": "pass"
},
"index": "source",
"query": {
"match": {
"test": "data"
}
}
},
"dest": {
"index": "dest"
}
}