Spec-Zone.ru › Elasticsearch 8
›Elasticsearch Guide [8.17] ›Ingest pipelines ›Ingest processor reference

Процессор Set

Устанавливает одно поле и связывает его со значением. Если поле уже существует, его значение заменяется указанным.

Таблица 41. Параметры процессора Set

Имя Обязательно По умолчанию Описание

field

да

-

Поле для вставки, обновления или изменения. Поддерживает фрагменты шаблонов.

value

да*

-

Значение для установки поля. Поддерживает фрагменты шаблонов. Можно указать только одно из value или copy_from.

copy_from

нет

-

Исходное поле, которое будет скопировано в field, нельзя одновременно устанавливать value. Поддерживаемые типы данных: boolean, number, array, object, string, date и т. д.

override

нет

true

Если процессор true будет обновлять поля с существующим полем с ненулевым значением. При установке в false такие поля не будут изменены.

ignore_empty_value

нет

false

Если процессор true используется в сочетании с value, которое является фрагментом шаблона, оцениваемым как null или пустая строка, процессор спокойно завершает работу без изменения документа. Аналогично, если используется в сочетании с copy_from, он спокойно завершится, если поле не существует или его значение оценивается как null или пустая строка.

media_type

нет

application/json

Тип содержимого для кодирования value. Применяется только тогда, когда value является фрагментом шаблона. Должно быть одним из application/json, text/plain или application/x-www-form-urlencoded.

description

нет

-

Описание процессора. Полезно для описания назначения процессора или его конфигурации.

if

нет

-

Условное выполнение процессора. См. Условное выполнение процессора.

ignore_failure

нет

false

Игнорировать ошибки для процессора. См. Обработка ошибок конвейера.

on_failure

нет

-

Обработка ошибок для процессора. См. Обработка ошибок конвейера.

tag

нет

-

Идентификатор процессора. Полезен для отладки и метрик.

{
  "description" : "sets the value of count to 1",
  "set": {
    "field": "count",
    "value": 1
  }
}

Этот процессор также может использоваться для копирования данных из одного поля в другое. Например:

resp = client.ingest.put_pipeline(
    id="set_os",
    description="sets the value of host.os.name from the field os",
    processors=[
        {
            "set": {
                "field": "host.os.name",
                "value": "{{{os}}}"
            }
        }
    ],
)
print(resp)

resp1 = client.ingest.simulate(
    id="set_os",
    docs=[
        {
            "_source": {
                "os": "Ubuntu"
            }
        }
    ],
)
print(resp1)
response = client.ingest.put_pipeline(
  id: 'set_os',
  body: {
    description: 'sets the value of host.os.name from the field os',
    processors: [
      {
        set: {
          field: 'host.os.name',
          value: '{{{os}}}'
        }
      }
    ]
  }
)
puts response

response = client.ingest.simulate(
  id: 'set_os',
  body: {
    docs: [
      {
        _source: {
          os: 'Ubuntu'
        }
      }
    ]
  }
)
puts response
const response = await client.ingest.putPipeline({
  id: "set_os",
  description: "sets the value of host.os.name from the field os",
  processors: [
    {
      set: {
        field: "host.os.name",
        value: "{{{os}}}",
      },
    },
  ],
});
console.log(response);

const response1 = await client.ingest.simulate({
  id: "set_os",
  docs: [
    {
      _source: {
        os: "Ubuntu",
      },
    },
  ],
});
console.log(response1);
PUT _ingest/pipeline/set_os
{
  "description": "sets the value of host.os.name from the field os",
  "processors": [
    {
      "set": {
        "field": "host.os.name",
        "value": "{{{os}}}"
      }
    }
  ]
}

POST _ingest/pipeline/set_os/_simulate
{
  "docs": [
    {
      "_source": {
        "os": "Ubuntu"
      }
    }
  ]
}

Результат:

{
  "docs" : [
    {
      "doc" : {
        "_index" : "_index",
        "_id" : "_id",
        "_version" : "-3",
        "_source" : {
          "host" : {
            "os" : {
              "name" : "Ubuntu"
            }
          },
          "os" : "Ubuntu"
        },
        "_ingest" : {
          "timestamp" : "2019-03-11T21:54:37.909224Z"
        }
      }
    }
  ]
}

Этот процессор также может обращаться к полям массива с использованием нотации точек:

resp = client.ingest.simulate(
    pipeline={
        "processors": [
            {
                "set": {
                    "field": "my_field",
                    "value": "{{{input_field.1}}}"
                }
            }
        ]
    },
    docs=[
        {
            "_index": "index",
            "_id": "id",
            "_source": {
                "input_field": [
                    "Ubuntu",
                    "Windows",
                    "Ventura"
                ]
            }
        }
    ],
)
print(resp)
response = client.ingest.simulate(
  body: {
    pipeline: {
      processors: [
        {
          set: {
            field: 'my_field',
            value: '{{{input_field.1}}}'
          }
        }
      ]
    },
    docs: [
      {
        _index: 'index',
        _id: 'id',
        _source: {
          input_field: [
            'Ubuntu',
            'Windows',
            'Ventura'
          ]
        }
      }
    ]
  }
)
puts response
const response = await client.ingest.simulate({
  pipeline: {
    processors: [
      {
        set: {
          field: "my_field",
          value: "{{{input_field.1}}}",
        },
      },
    ],
  },
  docs: [
    {
      _index: "index",
      _id: "id",
      _source: {
        input_field: ["Ubuntu", "Windows", "Ventura"],
      },
    },
  ],
});
console.log(response);
POST /_ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "set": {
          "field": "my_field",
          "value": "{{{input_field.1}}}"
        }
      }
    ]
  },
  "docs": [
    {
      "_index": "index",
      "_id": "id",
      "_source": {
        "input_field": [
          "Ubuntu",
          "Windows",
          "Ventura"
        ]
      }
    }
  ]
}

Результат:

{
  "docs": [
    {
      "doc": {
        "_index": "index",
        "_id": "id",
        "_version": "-3",
        "_source": {
          "input_field": [
            "Ubuntu",
            "Windows",
            "Ventura"
          ],
          "my_field": "Windows"
        },
        "_ingest": {
          "timestamp": "2023-05-05T16:04:16.456475214Z"
        }
      }
    }
  ]
}

Содержимое поля, включая сложные значения, такие как массивы и объекты, можно скопировать в другое поле, используя copy_from:

resp = client.ingest.put_pipeline(
    id="set_bar",
    description="sets the value of bar from the field foo",
    processors=[
        {
            "set": {
                "field": "bar",
                "copy_from": "foo"
            }
        }
    ],
)
print(resp)

resp1 = client.ingest.simulate(
    id="set_bar",
    docs=[
        {
            "_source": {
                "foo": [
                    "foo1",
                    "foo2"
                ]
            }
        }
    ],
)
print(resp1)
response = client.ingest.put_pipeline(
  id: 'set_bar',
  body: {
    description: 'sets the value of bar from the field foo',
    processors: [
      {
        set: {
          field: 'bar',
          copy_from: 'foo'
        }
      }
    ]
  }
)
puts response

response = client.ingest.simulate(
  id: 'set_bar',
  body: {
    docs: [
      {
        _source: {
          foo: [
            'foo1',
            'foo2'
          ]
        }
      }
    ]
  }
)
puts response
const response = await client.ingest.putPipeline({
  id: "set_bar",
  description: "sets the value of bar from the field foo",
  processors: [
    {
      set: {
        field: "bar",
        copy_from: "foo",
      },
    },
  ],
});
console.log(response);

const response1 = await client.ingest.simulate({
  id: "set_bar",
  docs: [
    {
      _source: {
        foo: ["foo1", "foo2"],
      },
    },
  ],
});
console.log(response1);
PUT _ingest/pipeline/set_bar
{
  "description": "sets the value of bar from the field foo",
  "processors": [
    {
      "set": {
        "field": "bar",
        "copy_from": "foo"
      }
    }
  ]
}

POST _ingest/pipeline/set_bar/_simulate
{
  "docs": [
    {
      "_source": {
        "foo": ["foo1", "foo2"]
      }
    }
  ]
}

Результат:

{
  "docs" : [
    {
      "doc" : {
        "_index" : "_index",
        "_id" : "_id",
        "_version" : "-3",
        "_source" : {
          "bar": ["foo1", "foo2"],
          "foo": ["foo1", "foo2"]
        },
        "_ingest" : {
          "timestamp" : "2020-09-30T12:55:17.742795Z"
        }
      }
    }
  ]
}

© 2023-2025 Elasticsearch
As of September 2024, Elasticsearch is available under a choice of three licenses: the Server Side Public License (SSPL), the Elastic License, or the AGPLv3 (OSI approved).
Elasticsearch and the Elasticsearch logo are trademarks of Elasticsearch B.V., registered in the U.S. and in other countries.
https://www.elastic.co/guide/en/elasticsearch/reference/8.17/set-processor.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API