1

我有一个 JSON 对象,其中一些字段如下:-

{
    "desc": "this is test description",
    "name": "some random name",
}

在索引此文档时,我想更改字段名称,索引后我的文档应如下所示:-

{
    "description": "this is test description",
    "user_name": "some random name",
}

我读过有关摄取管道处理器的信息,但它们仅在创建字段后重命名。有什么方法可以在索引时更改字段名称?

4

1 回答 1

2

做到这一点的方法是使用Pipeline. 一般的想法是您定义管道并在集群上为其命名。然后您可以在索引数据时引用它,并且您发送的数据将通过该管道传递以对其进行转换。注意管道只会在标记为“摄取”节点的节点上运行。

https://www.elastic.co/guide/en/elasticsearch/reference/current/pipeline.html

要具体重命名,您可以使用此处理器: https ://www.elastic.co/guide/en/elasticsearch/reference/current/rename-processor.html

我没有明确地对此进行测试,但代码将类似于:

使用名称在集群上定义管道:

PUT _ingest/pipeline/my-pipeline-name
{
  "description" : "rename user name",
  "processors" : [
    {
      "rename" : {
        "field": "name",
        "target_field": "user_name"
      },
      "rename" : {
        "field": "field2",
        "target_field": "newfield2"
      }
    }
  ]
}

使用管道加载您的文档:

POST /some_index/_doc/?pipeline=my-pipeline-name
{
    "desc": "this is test description",
    "name": "some random name",
}
于 2019-10-17T14:34:06.253 回答