類型映射、object
字段和nested
字段包含子字段,稱爲properties
,這些屬性能夠是任何數據類型,包括object
和nested
,能夠添加屬性:app
PUT mapping
API添加或更新映射類型時顯式地定義它們。下面是一個向映射類型、object
字段和nested
字段添加properties
的示例:code
PUT my_index { "mappings": { "properties": { "manager": { "properties": { "age": { "type": "integer" }, "name": { "type": "text" } } }, "employees": { "type": "nested", "properties": { "age": { "type": "integer" }, "name": { "type": "text" } } } } } } PUT my_index/_doc/1 { "region": "US", "manager": { "name": "Alice White", "age": 30 }, "employees": [ { "name": "John Smith", "age": 34 }, { "name": "Peter Brown", "age": 26 } ] }
manager
對象字段下的屬性。employees
嵌套字段下的屬性。properties
設置容許在同一索引中爲同名字段設置不一樣的設置,可使用PUT mapping
API將新屬性添加到現有字段。
內部字段能夠在查詢、聚合等中引用,使用點符號:對象
GET my_index/_search { "query": { "match": { "manager.name": "Alice White" } }, "aggs": { "Employees": { "nested": { "path": "employees" }, "aggs": { "Employee Ages": { "histogram": { "field": "employees.age", "interval": 5 } } } } } }
必須指定到內部字段的完整路徑。