对象字段类型
编辑对象字段类型
编辑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" } } }
在内部,此文档被索引为简单的键值对扁平列表,如下所示:
{ "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
,因为这是默认值。