Use Copy-to with different delimiters i.e "," , ";" etc

hi,

I am trying to concatenate two fields firstName and last name to build a field as fullName. After some R&D I have found copy-to feature in mapping that can help to copy fields to a certain field. But here I am trying to copy the two fields with certain delimiter e.g. ",". For instance,
firstName: Tom
firstName: Cruise
fullName: Tom, Cruise

Is there any option in copy-to to append delimiter with field.

Thanks in advance,
FA

No. You should do that with an ingest pipeline instead. Use the Set Processor.

POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "set": {
          "field": "fullName",
          "value": "{{firstName}}, {{lastName}}"
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "firstName": "Tom",
        "lastName": "Cruise"
      }
    }
  ]
}

Gives:

{
  "docs" : [
    {
      "doc" : {
        "_index" : "_index",
        "_type" : "_doc",
        "_id" : "_id",
        "_source" : {
          "firstName" : "Tom",
          "lastName" : "Cruise",
          "fullName" : "Tom, Cruise"
        },
        "_ingest" : {
          "timestamp" : "2020-05-20T09:07:54.674741Z"
        }
      }
    }
  ]
}

Thanks for the quick response. I have test the suggested solution for my scenario. Let me explain the scenario a bit. I have a customer index with mapping as follows:

{
    "customer": {
        "mappings": {
            "properties": {
                "country": {
                    "type": "text"
                },
                "language": {
                    "type": "text"
                },
                "firstName": {
                    "type": "text"
                },
                "lastName": {
                    "type": "text"
                },
                "middleName": {
                    "type": "text"
                },
                "fullName": {
                    "type": "text"
                }
            }
        }
    }
}

Then I have define a processor in the pipeline as suggested:
localhost:9200/_ingest/pipeline/fullName

{
    "processors": [
        {
            "set": {
                "field": "fullName",
                "value": "{{firstName}}, {{lastName}}"
            }
        }
    ]
}

after ingesting some data using the POST endpoint, when I query for search all records, still there is a null value for the fullName field in the response. Is there something wrong with my approach.

Could you provide a full recreation script as I did and as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

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