Elasticsearch copy_to field type

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

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 :

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

Welcome to the community @Ryze

Not sure your overall goal but a good way to do this would be to use in ingestion pipeline.

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.

PUT my-index-000001
{
  "mappings": {
    "properties": {
      "first_name": {
        "type": "text"
      },
      "last_name": {
        "type": "text"
      },
      "full_name": {
        "type": "keyword"
      }
    }
  }
}
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}}"
      }
    }
  ]
}
POST my-index-000001/_doc/1?pipeline=set_full_name
{
  "first_name": "Aaron",
  "last_name": "Nimocks"
}
1 Like

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

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.