Set processor

The set processor adds or updates fields in a document. It sets one field and associates it with the specified value. If the field already exists, then its value is replaced with the provided one unless the override parameter is set to false. When override is false and the specified field exists, the value of the field remains unchanged.

The following is the syntax for the set processor:

  1. {
  2. "description": "...",
  3. "processors": [
  4. {
  5. "set": {
  6. "field": "new_field",
  7. "value": "some_value"
  8. }
  9. }
  10. ]
  11. }

copy

Configuration parameters

The following table lists the required and optional parameters for the set processor.

ParameterRequired/OptionalDescription
fieldRequiredThe name of the field to be set or updated. Supports template snippets.
valueRequiredThe value assigned to the field. Supports template snippets.
overrideOptionalA Boolean flag that determines whether the processor should override the existing value of the field.
ignore_empty_valueOptionalA Boolean flag that determines whether the processor should ignore null values or empty strings. Default is false.
descriptionOptionalA description of the processor’s purpose or configuration.
ifOptionalSpecifies to conditionally execute the processor.
ignore_failureOptionalSpecifies to ignore processor failures. See Handling pipeline failures.
on_failureOptionalSpecifies a list of processors to run if the processor fails during execution. These processors are executed in the order they are specified.
tagOptionalAn identifier tag for the processor. Useful for debugging in order to distinguish between processors of the same type.

Using the processor

Follow these steps to use the processor in a pipeline.

Step 1: Create a pipeline

The following query creates a pipeline named set-pipeline that uses the set processor to add a new field new_field with the value some_value to the document:

  1. PUT _ingest/pipeline/set-pipeline
  2. {
  3. "description": "Adds a new field 'new_field' with the value 'some_value'",
  4. "processors": [
  5. {
  6. "set": {
  7. "field": "new_field",
  8. "value": "some_value"
  9. }
  10. }
  11. ]
  12. }

copy

Step 2 (Optional): Test the pipeline

It is recommended that you test your pipeline before you ingest documents.

To test the pipeline, run the following query:

  1. POST _ingest/pipeline/set-pipeline/_simulate
  2. {
  3. "docs": [
  4. {
  5. "_source": {
  6. "existing_field": "value"
  7. }
  8. }
  9. ]
  10. }

copy

Response

The following example response confirms that the pipeline is working as expected:

  1. {
  2. "docs": [
  3. {
  4. "doc": {
  5. "_index": "_index",
  6. "_id": "_id",
  7. "_source": {
  8. "existing_field": "value",
  9. "new_field": "some_value"
  10. },
  11. "_ingest": {
  12. "timestamp": "2024-05-30T21:56:15.066180712Z"
  13. }
  14. }
  15. }
  16. ]
  17. }

copy

Step 3: Ingest a document

The following query ingests a document into an index named testindex1:

  1. POST testindex1/_doc?pipeline=set-pipeline
  2. {
  3. "existing_field": "value"
  4. }

copy

Response

The request indexes the document into the index testindex1 and then indexes all documents with the new_field set to some_value, as shown in the following response:

  1. {
  2. "_index": "testindex1",
  3. "_id": "1",
  4. "_version": 1,
  5. "result": "created",
  6. "_shards": {
  7. "total": 2,
  8. "successful": 1,
  9. "failed": 0
  10. },
  11. "_seq_no": 0,
  12. "_primary_term": 1
  13. }

copy

Step 4 (Optional): Retrieve the document

To retrieve the document, run the following query:

  1. GET testindex1/_doc/1

copy