elasticsearch 如何将管道附加到索引

cvxl0en2  于 12个月前  发布在  ElasticSearch
关注(0)|答案(2)|浏览(109)

我创建了摄取管道,并添加了时间戳:

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}}"
      }
    }
  ]
}

上面的流水线将一个字段ingest_timestamp添加到每个具有当前时间戳值的文档中。
PUT my_index/_doc/1

{
  "foo": "bar"
}

如果我们现在检索这个文档,我们可以看到一个字段ingest_timestamp被添加到其中:

{
  "_index" : "my_index",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 1,
  "found" : true,
  "_source" : {
    "foo" : "bar",
    "ingest_timestamp" : "2018-12-12T12:04:09.921Z"
  }
}

如何将管道附加到当前索引?

xlpyo6sf

xlpyo6sf1#

有两种方法可以用您添加的字段更新所有文档

  1. Reindex API.一般来说-非常简单的解决方案。如果您需要保存索引的原始命名-您可以:
    a)重新索引到备份索引,b)删除原始索引,c)从备份重新索引到命名为前一个的新索引。
    1.在你的索引中有一点假。更棘手的是,你可以试试这样的东西。
    curl -XPOST localhost:9200/my_index/_update_by_query?pretty -d'{“script”:{“inline”:“ctx._source.foo = ctx._source.foo”},“query”:{“match_all”:联系我们
    你可以从这个例子中看到,这个想法是用相同的值更新值。你可以试试你自己的领域
gmol1639

gmol16392#

我想,在第一种方式中,我应该在目标索引中添加管道?例如

POST _reindex
{
  "source": {
    "index": "source",
  },
  "dest": {
    "index": "destination",
    "pipeline": "set-timestamp"
  }
}

虽然我检查了GET new_index/_doc/1没有显示新的时间戳字段。
仅仅更新索引设置还不够吗?

PUT /my-index-000001/_settings
    {
      "index" : {
        "default_pipeline": "set-timestamp"
      }
    }

相关问题