Spec-Zone.ru › Elasticsearch 8
›Elasticsearch Guide [8.17] ›Mapping ›Типы данных полей

Тип поля Object

JSON-документы иерархичны: документ может содержать вложенные объекты, которые, в свою очередь, могут содержать вложенные объекты:

resp = client.index(
    index="my-index-000001",
    id="1",
    document={
        "region": "US",
        "manager": {
            "age": 30,
            "name": {
                "first": "John",
                "last": "Smith"
            }
        }
    },
)
print(resp)
response = client.index(
  index: 'my-index-000001',
  id: 1,
  body: {
    region: 'US',
    manager: {
      age: 30,
      name: {
        first: 'John',
        last: 'Smith'
      }
    }
  }
)
puts response
const response = await client.index({
  index: "my-index-000001",
  id: 1,
  document: {
    region: "US",
    manager: {
      age: 30,
      name: {
        first: "John",
        last: "Smith",
      },
    },
  },
});
console.log(response);
PUT my-index-000001/_doc/1
{ 
  "region": "US",
  "manager": { 
    "age":     30,
    "name": { 
      "first": "John",
      "last":  "Smith"
    }
  }
}

Внешний документ также является JSON-объектом.

Он содержит вложенный объект, называемый manager.

Который, в свою очередь, содержит вложенный объект, называемый name.

Внутренне этот документ индексируется как простой, плоский список пар «ключ-значение», примерно так:

{
  "region":             "US",
  "manager.age":        30,
  "manager.name.first": "John",
  "manager.name.last":  "Smith"
}

Явное отображение для вышеупомянутого документа может выглядеть так:

resp = client.indices.create(
    index="my-index-000001",
    mappings={
        "properties": {
            "region": {
                "type": "keyword"
            },
            "manager": {
                "properties": {
                    "age": {
                        "type": "integer"
                    },
                    "name": {
                        "properties": {
                            "first": {
                                "type": "text"
                            },
                            "last": {
                                "type": "text"
                            }
                        }
                    }
                }
            }
        }
    },
)
print(resp)
response = client.indices.create(
  index: 'my-index-000001',
  body: {
    mappings: {
      properties: {
        region: {
          type: 'keyword'
        },
        manager: {
          properties: {
            age: {
              type: 'integer'
            },
            name: {
              properties: {
                first: {
                  type: 'text'
                },
                last: {
                  type: 'text'
                }
              }
            }
          }
        }
      }
    }
  }
)
puts response
const response = await client.indices.create({
  index: "my-index-000001",
  mappings: {
    properties: {
      region: {
        type: "keyword",
      },
      manager: {
        properties: {
          age: {
            type: "integer",
          },
          name: {
            properties: {
              first: {
                type: "text",
              },
              last: {
                type: "text",
              },
            },
          },
        },
      },
    },
  },
});
console.log(response);
PUT my-index-000001
{
  "mappings": {
    "properties": { 
      "region": {
        "type": "keyword"
      },
      "manager": { 
        "properties": {
          "age":  { "type": "integer" },
          "name": { 
            "properties": {
              "first": { "type": "text" },
              "last":  { "type": "text" }
            }
          }
        }
      }
    }
  }
}

Свойства в определении отображения верхнего уровня.

Поле manager является вложенным полем object.

Поле manager.name — это вложенное поле object внутри поля manager.

Не требуется явно устанавливать поле type в значение object, так как это значение по умолчанию.

Параметры для полей object

Следующие параметры принимаются полями типа object:

dynamic

Нужно ли динамически добавлять новые properties в существующий объект. Принимает значения true (по умолчанию), runtime, false и strict.

enabled

Нужно ли парсить и индексировать JSON-значение, заданное для поля объекта (true, по умолчанию), или полностью игнорировать его (false).

subobjects

Может ли объект содержать вложенные объекты (true, по умолчанию) или нет (false). Если нет, подполя с точками в именах будут обрабатываться как листья, в противном случае их имена полей будут расширены до соответствующей структуры объекта.

properties

Поля внутри объекта, которые могут быть любого типа данных, включая object. Новые свойства могут быть добавлены в существующий объект.

Если вам нужно индексировать массивы объектов вместо отдельных объектов, сначала прочитайте раздел Nested.

© 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/object.html

Spec-Zone.ru

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