简体   繁体   English

在Elasticsearch中,如何将数据从一个字段移到另一字段

[英]In Elasticsearch, how to move data from one field into another field

I have an index with mappings that look like this: 我有一个带有映射的索引,如下所示:

"mappings": {
  "default": {
    "_all": {
      "enabled": false
    },
    "properties": {
      "Foo": {
        "properties": {
          "Bar": {
            "type": "keyword"
          }
      }
    }
  }
}

I am trying to change the mapping to introduce a sub-field of Bar, called Code, whilst migrating the string currently in Bar into Bar.Code. 我试图更改映射以引入Bar的子字段(称为Code),同时将Bar中当前的字符串迁移到Bar.Code中。 Here is the new mapping: 这是新的映射:

"mappings": {
  "default": {
    "_all": {
      "enabled": false
    },
    "properties": {
      "Foo": {
        "properties": {
          "Bar": {
            "properties": {
              "Code": {
                "type": "keyword"
              }
            }
          }
      }
    }
  }
}

In order to do this, I think I need to do a _reindex and specify a pipeline. 为了做到这一点,我认为我需要做一个_reindex并指定一个管道。 Is that correct? 那是对的吗? If so, how does my pipeline access the original data? 如果是这样,我的管道如何访问原始数据?

I have tried variations on the following code, but without success: 我尝试了以下代码的变体,但没有成功:

PUT _ingest/pipeline/transformFooBar
{
    "processors": [
      {
        "set": {
          "field": "Bar.Code",
          "value": "{{_source.Bar}}"
        }
      }
    ]
}

POST _reindex
{
  "source": {
    "index": "foo_v1"
  },
  "dest": {
    "index": "foo_v2",
    "pipeline": "transformFooBar"
  }
}

Ah, I almost had the syntax right. 啊,我的语法几乎正确。 The _source is not required: 不需要_source:

// Create a pipeline with a SET processor
PUT _ingest/pipeline/transformFooBar
{
    "processors": [
      {
        "set": {
          "field": "Bar.Code",
          "value": "{{Bar}}"
        }
      }
    ]
}

// Reindex using the above pipeline
POST _reindex
{
  "source": {
    "index": "foo_v1"
  },
  "dest": {
    "index": "foo_v2",
    "pipeline": "transformFooBar"
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 elasticsearch 数据从一台服务器移动到另一台服务器 - how to move elasticsearch data from one server to another 如何从查询中返回一个字段(Spring Data Elasticsearch) - How to return one field from a query (Spring Data Elasticsearch) 通过spring数据从elasticsearch获得一个字段 - get one field from elasticsearch by spring data ElasticSearch:如何使用现有数据将字段移到另一个级别? - ElasticSearch: How to move a field to a different level with existing data? 如何将ElasticSearch字段复制到另一个字段 - how to copy ElasticSearch field to another field 如何有效地将数据从Elasticsearch索引(具有一个分片)移动到另一索引(具有5个分片)? - How to efficiently move data from elasticsearch index (with one shard) to another index (with 5 shards)? 如何将所有 elasticsearch 分片从一个节点移动到另一个节点? - How to move all elasticsearch shards from one node to another? Elasticsearch:查找一个字段与另一个字段的重叠 - Elasticsearch: Finding the overlap of one field against another 如何从 elasticsearch 获取数据,其中一个字段是其他字段的组合 - How to get data from elasticsearch where one field is combination of other fields 如何在Elasticsearch中启用字段数据 - How to enable field data in elasticsearch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM