2013-10-14 02:53:07 -04:00
|
|
|
[[indices-get-field-mapping]]
|
|
|
|
== Get Field Mapping
|
|
|
|
|
|
|
|
The get field mapping API allows you to retrieve mapping definitions for one or more fields.
|
|
|
|
This is useful when you do not need the complete type mapping returned by
|
|
|
|
the <<indices-get-mapping>> API.
|
|
|
|
|
2017-02-03 04:04:31 -05:00
|
|
|
For example, consider the following mapping:
|
2013-10-14 02:53:07 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2019-01-18 08:11:18 -05:00
|
|
|
PUT publications
|
2017-02-03 04:04:31 -05:00
|
|
|
{
|
|
|
|
"mappings": {
|
2019-01-18 08:11:18 -05:00
|
|
|
"properties": {
|
|
|
|
"id": { "type": "text" },
|
|
|
|
"title": { "type": "text"},
|
|
|
|
"abstract": { "type": "text"},
|
|
|
|
"author": {
|
|
|
|
"properties": {
|
|
|
|
"id": { "type": "text" },
|
|
|
|
"name": { "type": "text" }
|
2017-02-03 04:04:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-14 02:53:07 -04:00
|
|
|
--------------------------------------------------
|
2017-02-03 04:04:31 -05:00
|
|
|
// TESTSETUP
|
2016-09-01 13:05:22 -04:00
|
|
|
// CONSOLE
|
2013-10-14 02:53:07 -04:00
|
|
|
|
2017-02-03 04:04:31 -05:00
|
|
|
The following returns the mapping of the field `title` only:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2019-01-14 16:08:01 -05:00
|
|
|
GET publications/_mapping/field/title
|
2017-02-03 04:04:31 -05:00
|
|
|
--------------------------------------------------
|
|
|
|
// CONSOLE
|
|
|
|
|
|
|
|
For which the response is:
|
2013-10-14 02:53:07 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
2017-02-03 04:04:31 -05:00
|
|
|
"publications": {
|
2016-09-01 13:05:22 -04:00
|
|
|
"mappings": {
|
2019-01-14 16:08:01 -05:00
|
|
|
"title": {
|
|
|
|
"full_name": "title",
|
|
|
|
"mapping": {
|
|
|
|
"title": {
|
|
|
|
"type": "text"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-14 02:53:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-09-01 13:05:22 -04:00
|
|
|
// TESTRESPONSE
|
2013-10-14 02:53:07 -04:00
|
|
|
|
|
|
|
[float]
|
2019-01-14 16:08:01 -05:00
|
|
|
=== Multiple Indices and Fields
|
2013-10-14 02:53:07 -04:00
|
|
|
|
2019-01-14 16:08:01 -05:00
|
|
|
The get field mapping API can be used to get the mapping of multiple fields from more than one index
|
2013-10-14 02:53:07 -04:00
|
|
|
with a single call. General usage of the API follows the
|
2019-01-14 16:08:01 -05:00
|
|
|
following syntax: `host:port/{index}/_mapping/field/{field}` where
|
|
|
|
`{index}` and `{field}` can stand for comma-separated list of names or wild cards. To
|
2013-10-14 02:53:07 -04:00
|
|
|
get mappings for all indices you can use `_all` for `{index}`. The
|
|
|
|
following are some examples:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2016-09-01 13:05:22 -04:00
|
|
|
GET /twitter,kimchy/_mapping/field/message
|
2013-10-14 02:53:07 -04:00
|
|
|
|
2019-01-14 16:08:01 -05:00
|
|
|
GET /_all/_mapping/field/message,user.id
|
2013-12-06 15:40:54 -05:00
|
|
|
|
2019-01-14 16:08:01 -05:00
|
|
|
GET /_all/_mapping/field/*.id
|
2013-10-14 02:53:07 -04:00
|
|
|
--------------------------------------------------
|
2016-09-01 13:05:22 -04:00
|
|
|
// CONSOLE
|
|
|
|
// TEST[setup:twitter]
|
|
|
|
// TEST[s/^/PUT kimchy\nPUT book\n/]
|
2013-10-14 02:53:07 -04:00
|
|
|
|
|
|
|
[float]
|
|
|
|
=== Specifying fields
|
|
|
|
|
2017-02-03 04:04:31 -05:00
|
|
|
The get mapping api allows you to specify a comma-separated list of fields.
|
2013-10-14 02:53:07 -04:00
|
|
|
|
2017-02-03 04:04:31 -05:00
|
|
|
For instance to select the `id` of the `author` field, you must use its full name `author.id`.
|
2013-10-14 02:53:07 -04:00
|
|
|
|
2017-02-03 04:04:31 -05:00
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2019-01-14 16:08:01 -05:00
|
|
|
GET publications/_mapping/field/author.id,abstract,name
|
2017-02-03 04:04:31 -05:00
|
|
|
--------------------------------------------------
|
|
|
|
// CONSOLE
|
2013-10-14 02:53:07 -04:00
|
|
|
|
2017-02-03 04:04:31 -05:00
|
|
|
returns:
|
2013-10-14 02:53:07 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2017-02-03 04:04:31 -05:00
|
|
|
{
|
|
|
|
"publications": {
|
|
|
|
"mappings": {
|
2019-01-14 16:08:01 -05:00
|
|
|
"author.id": {
|
|
|
|
"full_name": "author.id",
|
|
|
|
"mapping": {
|
|
|
|
"id": {
|
|
|
|
"type": "text"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"abstract": {
|
|
|
|
"full_name": "abstract",
|
|
|
|
"mapping": {
|
|
|
|
"abstract": {
|
|
|
|
"type": "text"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-03 04:04:31 -05:00
|
|
|
}
|
|
|
|
}
|
2013-10-14 02:53:07 -04:00
|
|
|
--------------------------------------------------
|
2017-02-03 04:04:31 -05:00
|
|
|
// TESTRESPONSE
|
2013-10-14 02:53:07 -04:00
|
|
|
|
2017-02-03 04:04:31 -05:00
|
|
|
The get field mapping API also supports wildcard notation.
|
2013-10-14 02:53:07 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2019-01-14 16:08:01 -05:00
|
|
|
GET publications/_mapping/field/a*
|
2013-10-14 02:53:07 -04:00
|
|
|
--------------------------------------------------
|
2017-02-03 04:04:31 -05:00
|
|
|
// CONSOLE
|
2013-10-14 02:53:07 -04:00
|
|
|
|
|
|
|
returns:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"publications": {
|
2017-02-03 04:04:31 -05:00
|
|
|
"mappings": {
|
2019-01-14 16:08:01 -05:00
|
|
|
"author.name": {
|
|
|
|
"full_name": "author.name",
|
|
|
|
"mapping": {
|
|
|
|
"name": {
|
|
|
|
"type": "text"
|
2017-02-03 04:04:31 -05:00
|
|
|
}
|
2019-01-14 16:08:01 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"abstract": {
|
|
|
|
"full_name": "abstract",
|
|
|
|
"mapping": {
|
|
|
|
"abstract": {
|
|
|
|
"type": "text"
|
2017-02-03 04:04:31 -05:00
|
|
|
}
|
2019-01-14 16:08:01 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"author.id": {
|
|
|
|
"full_name": "author.id",
|
|
|
|
"mapping": {
|
|
|
|
"id": {
|
|
|
|
"type": "text"
|
2017-02-03 04:04:31 -05:00
|
|
|
}
|
2013-10-14 02:53:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2017-02-03 04:04:31 -05:00
|
|
|
// TESTRESPONSE
|
2013-10-14 02:53:07 -04:00
|
|
|
|
|
|
|
[float]
|
|
|
|
=== Other options
|
|
|
|
|
|
|
|
[horizontal]
|
2014-05-06 11:21:09 -04:00
|
|
|
`include_defaults`::
|
|
|
|
|
|
|
|
adding `include_defaults=true` to the query string will cause the response
|
|
|
|
to include default values, which are normally suppressed.
|