Get field mapping API
editGet field mapping API
editRetrieves mapping definitions for one or more fields. This is useful if you don’t need the complete mapping of an index or your index contains a large number of fields.
GET /my-index-000001/_mapping/field/user
Path parameters
edit-
<index>
- (Optional, string) Comma-separated list or wildcard expression of index names used to limit the request.
-
<field>
- (Optional, string) Comma-separated list or wildcard expression of fields used to limit returned information.
Query parameters
edit-
allow_no_indices
-
(Optional, boolean) If
true
, the request does not return an error if a wildcard expression or_all
value retrieves only missing or closed indices.This parameter also applies to index aliases that point to a missing or closed index.
Defaults to
true
. -
expand_wildcards
-
(Optional, string) Controls what kind of indices that wildcard expressions can expand to. Multiple values are accepted when separated by a comma, as in
open,hidden
. Valid values are:-
all
- Expand to open and closed indices, including hidden indices.
-
open
- Expand only to open indices.
-
closed
- Expand only to closed indices.
-
hidden
-
Expansion of wildcards will include hidden indices.
Must be combined with
open
,closed
, or both. -
none
- Wildcard expressions are not accepted.
-
-
include_type_name
-
[7.0.0]
Deprecated in 7.0.0. Mapping types have been deprecated. See Removal of mapping types.
(Optional, boolean) If
true
, a mapping type is expected in the body of mappings. Defaults tofalse
. -
ignore_unavailable
-
(Optional, boolean) If
true
, missing or closed indices are not included in the response. Defaults tofalse
. -
include_defaults
-
(Optional, boolean) If
true
, the response includes default mapping values. Defaults tofalse
. -
local
-
[7.8.0]
Deprecated in 7.8.0. This parameter is a no-op and field mappings are always retrieved locally
(Optional, boolean) If
true
, the request retrieves information from the local node only. Defaults tofalse
, which means information is retrieved from the master node.
Examples
editExample with index setup
editYou can provide field mappings when creating a new index. The following
create index API request creates the publications
index with several field mappings.
PUT /publications { "mappings": { "properties": { "id": { "type": "text" }, "title": { "type": "text" }, "abstract": { "type": "text" }, "author": { "properties": { "id": { "type": "text" }, "name": { "type": "text" } } } } } }
The following returns the mapping of the field title
only:
GET publications/_mapping/field/title
The API returns the following response:
{ "publications": { "mappings": { "title": { "full_name": "title", "mapping": { "title": { "type": "text" } } } } } }
Specifying fields
editThe get mapping api allows you to specify a comma-separated list of fields.
For instance to select the id
of the author
field, you must use its full name author.id
.
GET publications/_mapping/field/author.id,abstract,name
returns:
{ "publications": { "mappings": { "author.id": { "full_name": "author.id", "mapping": { "id": { "type": "text" } } }, "abstract": { "full_name": "abstract", "mapping": { "abstract": { "type": "text" } } } } } }
The get field mapping API also supports wildcard notation.
GET publications/_mapping/field/a*
returns:
{ "publications": { "mappings": { "author.name": { "full_name": "author.name", "mapping": { "name": { "type": "text" } } }, "abstract": { "full_name": "abstract", "mapping": { "abstract": { "type": "text" } } }, "author.id": { "full_name": "author.id", "mapping": { "id": { "type": "text" } } } } } }
Multiple indices and fields
editThe get field mapping API can be used to get the mapping of multiple fields from more than one index
with a single call. General usage of the API follows the
following syntax: host:port/<index>/_mapping/field/<field>
where
<index>
and <field>
can stand for comma-separated list of names or wild cards. To
get mappings for all indices you can use _all
for <index>
. The
following are some examples:
GET /my-index-000001,my-index-000002/_mapping/field/message GET /_all/_mapping/field/message,user.id GET /_all/_mapping/field/*.id