原英文版地址: https://www.elastic.co/guide/en/elasticsearch/reference/7.7/search-field-caps.html, 原文档版权归 www.elastic.co 所有
本地英文版地址: ../en/search-field-caps.html

Field Capabilities APIedit

Allows you to retrieve the capabilities of fields among multiple indices.

GET /_field_caps?fields=rating

Requestedit

GET /_field_caps

POST /_field_caps

GET /<index>/_field_caps

POST /<index>/_field_caps

Descriptionedit

The field capabilities API returns the information about the capabilities of fields among multiple indices.

Path parametersedit

<index>
(Optional, string) Comma-separated list or wildcard expression of index names used to limit the request.

Query parametersedit

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.

Defaults to open.

fields

(Optional, string) Comma-separated list or wildcard expressions of fields to include in the statistics.

Used as the default list unless a specific field list is provided in the completion_fields or fielddata_fields parameters.

ignore_unavailable
(Optional, boolean) If true, missing or closed indices are not included in the response. Defaults to false.
include_unmapped
(Optional, boolean) If true, unmapped fields are included in the response. Defaults to false.

Response bodyedit

searchable
Whether this field is indexed for search on all indices.
aggregatable
Whether this field can be aggregated on all indices.
indices
The list of indices where this field has the same type, or null if all indices have the same type for the field.
non_searchable_indices
The list of indices where this field is not searchable, or null if all indices have the same definition for the field.
non_aggregatable_indices
The list of indices where this field is not aggregatable, or null if all indices have the same definition for the field.
meta
Merged metadata across all indices as a map of string keys to arrays of values. A value length of 1 indicates that all indices had the same value for this key, while a length of 2 or more indicates that not all indices had the same value for this key.

Examplesedit

The request can be restricted to specific indices:

GET twitter/_field_caps?fields=rating

The next example API call requests information about the rating and the title fields:

GET _field_caps?fields=rating,title

The API returns the following response:

{
    "indices": ["index1", "index2", "index3", "index4", "index5"],
    "fields": {
        "rating": { 
            "long": {
                "searchable": true,
                "aggregatable": false,
                "indices": ["index1", "index2"],
                "non_aggregatable_indices": ["index1"] 
            },
            "keyword": {
                "searchable": false,
                "aggregatable": true,
                "indices": ["index3", "index4"],
                "non_searchable_indices": ["index4"] 
            }
        },
        "title": { 
            "text": {
                "searchable": true,
                "aggregatable": false

            }
        }
    }
}

The field rating is defined as a long in index1 and index2 and as a keyword in index3 and index4.

The field rating is not aggregatable in index1.

The field rating is not searchable in index4.

The field title is defined as text in all indices.

By default unmapped fields are ignored. You can include them in the response by adding a parameter called include_unmapped in the request:

GET _field_caps?fields=rating,title&include_unmapped

In which case the response will contain an entry for each field that is present in some indices but not all:

{
    "indices": ["index1", "index2", "index3"],
    "fields": {
        "rating": {
            "long": {
                "searchable": true,
                "aggregatable": false,
                "indices": ["index1", "index2"],
                "non_aggregatable_indices": ["index1"]
            },
            "keyword": {
                "searchable": false,
                "aggregatable": true,
                "indices": ["index3", "index4"],
                "non_searchable_indices": ["index4"]
            },
            "unmapped": { 
                "indices": ["index5"],
                "searchable": false,
                "aggregatable": false
            }
        },
        "title": {
            "text": {
                "indices": ["index1", "index2", "index3", "index4"],
                "searchable": true,
                "aggregatable": false
            },
            "unmapped": { 
                "indices": ["index5"]
                "searchable": false,
                "aggregatable": false
            }
        }
    }
}

The rating field is unmapped` in index5.

The title field is unmapped` in index5.