Тип поля 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-объектом. | |
| Он содержит вложенный объект, называемый | |
| Который, в свою очередь, содержит вложенный объект, называемый |
Внутренне этот документ индексируется как простой, плоский список пар «ключ-значение», примерно так:
{
"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" }
}
}
}
}
}
}
} | Свойства в определении отображения верхнего уровня. | |
| Поле | |
| Поле |
Не требуется явно устанавливать поле type в значение object, так как это значение по умолчанию.
Параметры для полей object
Следующие параметры принимаются полями типа object:
| Нужно ли динамически добавлять новые | |
| Нужно ли парсить и индексировать JSON-значение, заданное для поля объекта ( | |
| Может ли объект содержать вложенные объекты ( | |
| Поля внутри объекта, которые могут быть любого типа данных, включая |
Если вам нужно индексировать массивы объектов вместо отдельных объектов, сначала прочитайте раздел 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