題目
index1中如果包含reindexBatch字段胞此,Reindex到index2中則加一根灯,否則設(shè)置為1
直接腳本方式
### 添加腳本
POST _scripts/control_reindex_batch
{
"script": {
"lang": "painless",
"source": """
if (ctx._source['reindexBatch'] != null) {
ctx._source['reindexBatch'] += params.increment;
} else {
ctx._source['reindexBatch'] = 1;
}
"""
}
}
### reindex
POST _reindex
{
"source": {
"index": "test_1"
},
"dest": {
"index": "test_3"
},
"script": {
"id": "control_reindex_batch",
"params": {
"increment": 1
}
}
}
使用ingest乙墙,間接腳本方式
PUT _ingest/pipeline/ig3
{
"description": "",
"processors": [
{
"script": {
"source": """
if (ctx.reindexBatch != null) {
ctx.reindexBatch += params.increment;
} else {
ctx.reindexBatch = 1;
}
""",
"params": {
"increment":1
}
}
}
]
}
POST _reindex
{
"source": {
"index": "test_1"
},
"dest": {
"index": "test_4",
"pipeline": "ig3"
}
}
樣例數(shù)據(jù)
PUT test_1/_bulk
{"index":{"_index":"test_1","_id":0}}
{"foo":[" adsa 123 "," 21232 321"],"firstname":"Li","lastname":"xiaolong"}
{"index":{"_index":"test_1","_id":1}}
{"foo":[" adsa 123 "," 21232 321"],"firstname":"Li","lastname":"xiaolong","reindexBatch":1}
使用script和ingest的區(qū)別
- 1,使用ingest的中腳本窄锅,使用字段時是不需要帶_source
- 2, 直接使用script加不加_source需要參考painless文檔
- 3偎箫,ingest靈活性差點木柬,但是可以通過_simulate驗證腳本的正確性
- 4,直接使用script淹办,靈活性強眉枕,但是不太好驗證