# Elasticsearch copy\_to field type

**URL:** <https://discuss.elastic.co/t/elasticsearch-copy-to-field-type/260333>\
**Category:** Elasticsearch\
**Created:** [January 6, 2021, 11:30am UTC](https://discuss.elastic.co/t/elasticsearch-copy-to-field-type/260333 "2021-01-06T11:30:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryze](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ryze/32/81828_2.png) [@Ryze](https://discuss.elastic.co/u/Ryze)\
**Post date:** [January 6, 2021, 11:30am UTC](https://discuss.elastic.co/t/elasticsearch-copy-to-field-type/260333/1 "2021-01-06T11:30:45Z")

</div>

I wonder that if the type of destination field of _ **copy\_to** _ must be _ **text** _ type. I have not find the description in the official document. [https://www.elastic.co/guide/en/elasticsearch/reference/current/copy-to.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/copy-to.html)

In other words,can the _ **full\_name** _ 's type be other type(such as keyword,search-as-you-type ...) but not text? Thanks.

Related question on StackOverflow :

> <https://stackoverflow.com/questions/65591650/elasticsearch-copy-to-field-type>

```auto
PUT my-index-000001
{
  "mappings": {
    "properties": {
      "first_name": {
        "type": "text",
        "copy_to": "full_name" 
      },
      "last_name": {
        "type": "text",
        "copy_to": "full_name" 
      },
      "full_name": {
        "type": "text"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [January 6, 2021, 12:46pm UTC](https://discuss.elastic.co/t/elasticsearch-copy-to-field-type/260333/2 "2021-01-06T12:46:32Z")

</div>

Welcome to the community @Ryze

Not sure your overall goal but a good way to do this would be to use in [ingestion pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/current/set-processor.html).

When you ingest data you specify the pipeline ID and that will do the combining of the names. You can set the mapping for the field to whatever you want.

```auto
PUT my-index-000001
{
  "mappings": {
    "properties": {
      "first_name": {
        "type": "text"
      },
      "last_name": {
        "type": "text"
      },
      "full_name": {
        "type": "keyword"
      }
    }
  }
}

```

```auto
PUT _ingest/pipeline/set_full_name
{
  "description": "Creates full name based on first and last",
  "processors": [
    {
      "set": {
        "field": "full_name",
        "value": "{{first_name}} {{last_name}}"
      }
    }
  ]
}

```

```auto
POST my-index-000001/_doc/1?pipeline=set_full_name
{
  "first_name": "Aaron",
  "last_name": "Nimocks"
}

```

---

<div class="post-metadata">

**Author:** ![Ryze](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ryze/32/81828_2.png) [@Ryze](https://discuss.elastic.co/u/Ryze)\
**Post date:** [January 7, 2021, 2:29am UTC](https://discuss.elastic.co/t/elasticsearch-copy-to-field-type/260333/3 "2021-01-07T02:29:17Z")

</div>

Dear aaron-nimocks, thank you very much for your reply. I can understand what you said.In fact, I am new to Elasticsearch and have no big goals to achieve.

The reason I ask this question is because when I read the official elasticsearch documentation (v7.10), _ **copy\_to** _ confuses me.

I have experimented with two situations myself.

In the first, I set the target field of the _ **copy\_to** _ to _ **keyword** _ type ,and the index can be created successfully, but the results cannot be searched according to my expectations.

In the second case, I set the target type of the _ **copy\_to** _ field to _ **search\_as\_you\_type** _ type,and the index can be created successfully, and the results can be searched as expected.

The experiment process can be found in the following document: [https://github.com/ZhangDi-d/elasticsearch-demo/blob/main/copy\_to.md](https://github.com/ZhangDi-d/elasticsearch-demo/blob/main/copy_to.md)

So I fell into a huge confusion. Did i do something wrong, or the _ **copy\_to** _ field does have type restrictions? I hope my description is clear and I hope you can give me some advice.

Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 4, 2021, 2:29am UTC](https://discuss.elastic.co/t/elasticsearch-copy-to-field-type/260333/4 "2021-02-04T02:29:19Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
