Reputation: 367
I created ingest pipeline with adding timestamp according:
PUT _ingest/pipeline/my_timestamp_pipeline
{
"description": "Adds a field to a document with the time of ingestion",
"processors": [
{
"set": {
"field": "ingest_timestamp",
"value": "{{_ingest.timestamp}}"
}
}
]
}
The pipeline above adds a field ingest_timestamp to every document with the value of the current timestamp.
PUT my_index/_doc/1
{
"foo": "bar"
}
If we now retrieve this document, we can see that a field ingest_timestamp was added to it:
{
"_index" : "my_index",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"found" : true,
"_source" : {
"foo" : "bar",
"ingest_timestamp" : "2018-12-12T12:04:09.921Z"
}
}
And how to attach pipeline to current index?
Upvotes: 0
Views: 351
Reputation: 367
I suppose that in the first way I should add pipeline in destination index? e.g.
POST _reindex
{
"source": {
"index": "source",
},
"dest": {
"index": "destination",
"pipeline": "set-timestamp"
}
}
Though I checked through GET new_index/_doc/1
doesn't show new timestamp fields.
Isn't it enough to just update index settings?
PUT /my-index-000001/_settings
{
"index" : {
"default_pipeline": "set-timestamp"
}
}
Upvotes: 0
Reputation: 442
There are 2 ways of updating all docs with that field you added
Reindex API. In general - very simple solution. If you need to save original naming of the index - you can :
a) reindex to backup_index, b) delete original index, c) reindex from backup to new index named as previous one.
Kinda fake update all docs in you index. A little bit more tricky, you can try something like this.
curl -XPOST localhost:9200/my_index/_update_by_query?pretty -d'{ "script": {"inline": "ctx._source.foo = ctx._source.foo" }, "query": { "match_all": {} }}'
You can see from the example that the idea is to update value with same value. You can try your own field
Upvotes: 0