OpenSearch/docs/reference/mapping/params/properties.asciidoc

105 lines
2.5 KiB
Plaintext
Raw Normal View History

[[properties]]
=== `properties`
Type mappings, <<object,`object` fields>> and <<nested,`nested` fields>>
contain sub-fields, called `properties`. These properties may be of any
<<mapping-types,datatype>>, including `object` and `nested`. Properties can
be added:
* explicitly by defining them when <<indices-create-index,creating an index>>.
2016-02-09 05:07:32 -05:00
* explicitly by defining them when adding or updating a mapping type with the <<indices-put-mapping,PUT mapping>> API.
* <<dynamic-mapping,dynamically>> just by indexing documents containing new fields.
Below is an example of adding `properties` to a mapping type, an `object`
field, and a `nested` field:
[source,js]
--------------------------------------------------
Update the default for include_type_name to false. (#37285) * Default include_type_name to false for get and put mappings. * Default include_type_name to false for get field mappings. * Add a constant for the default include_type_name value. * Default include_type_name to false for get and put index templates. * Default include_type_name to false for create index. * Update create index calls in REST documentation to use include_type_name=true. * Some minor clean-ups around the get index API. * In REST tests, use include_type_name=true by default for index creation. * Make sure to use 'expression == false'. * Clarify the different IndexTemplateMetaData toXContent methods. * Fix FullClusterRestartIT#testSnapshotRestore. * Fix the ml_anomalies_default_mappings test. * Fix GetFieldMappingsResponseTests and GetIndexTemplateResponseTests. We make sure to specify include_type_name=true during xContent parsing, so we continue to test the legacy typed responses. XContent generation for the typeless responses is currently only covered by REST tests, but we will be adding unit test coverage for these as we implement each typeless API in the Java HLRC. This commit also refactors GetMappingsResponse to follow the same appraoch as the other mappings-related responses, where we read include_type_name out of the xContent params, instead of creating a second toXContent method. This gives better consistency in the response parsing code. * Fix more REST tests. * Improve some wording in the create index documentation. * Add a note about types removal in the create index docs. * Fix SmokeTestMonitoringWithSecurityIT#testHTTPExporterWithSSL. * Make sure to mention include_type_name in the REST docs for affected APIs. * Make sure to use 'expression == false' in FullClusterRestartIT. * Mention include_type_name in the REST templates docs.
2019-01-14 16:08:01 -05:00
PUT my_index?include_type_name=true
{
"mappings": {
"_doc": { <1>
"properties": {
"manager": { <2>
"properties": {
"age": { "type": "integer" },
2016-03-18 12:01:27 -04:00
"name": { "type": "text" }
}
},
"employees": { <3>
"type": "nested",
"properties": {
"age": { "type": "integer" },
2016-03-18 12:01:27 -04:00
"name": { "type": "text" }
}
}
}
}
}
}
PUT my_index/_doc/1 <4>
{
"region": "US",
"manager": {
"name": "Alice White",
"age": 30
},
"employees": [
{
"name": "John Smith",
"age": 34
},
{
"name": "Peter Brown",
"age": 26
}
]
}
--------------------------------------------------
// CONSOLE
<1> Properties under the `_doc` mapping type.
<2> Properties under the `manager` object field.
<3> Properties under the `employees` nested field.
<4> An example document which corresponds to the above mapping.
TIP: The `properties` setting is allowed to have different settings for fields
of the same name in the same index. New properties can be added to existing
fields using the <<indices-put-mapping,PUT mapping API>>.
==== Dot notation
Inner fields can be referred to in queries, aggregations, etc., using _dot
notation_:
[source,js]
--------------------------------------------------
GET my_index/_search
{
"query": {
"match": {
"manager.name": "Alice White"
}
},
"aggs": {
"Employees": {
"nested": {
"path": "employees"
},
"aggs": {
"Employee Ages": {
"histogram": {
"field": "employees.age",
"interval": 5
}
}
}
}
}
}
--------------------------------------------------
// CONSOLE
// TEST[continued]
IMPORTANT: The full path to the inner field must be specified.