原文地址: https://www.elastic.co/guide/en/elasticsearch/reference/7.7/indices-segments.html, 原文档版权归 www.elastic.co 所有

Index segments APIedit

Returns low-level information about the Lucene segments in index shards.

GET /twitter/_segments

Requestedit

GET /<index>/_segments

GET /_segments

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.

ignore_unavailable
(Optional, boolean) If true, missing or closed indices are not included in the response. Defaults to false.
verbose
[experimental] This functionality is experimental and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features. (Optional, boolean) If true, the response includes detailed information about Lucene’s memory usage. Defaults to false.

Response bodyedit

<segment>
(String) Name of the segment, such as _0. The segment name is derived from the segment generation and used internally to create file names in the directory of the shard.
generation
(Integer) Generation number, such as 0. Elasticsearch increments this generation number for each segment written. Elasticsearch then uses this number to derive the segment name. Generation number, such as 0. Elasticsearch increments this generation number for each segment written. Elasticsearch then uses this number to derive the segment name.
num_docs
(Integer) Number of non-deleted documents in the segment, such as 25. This number is based on Lucene documents and may include documents from nested fields.
deleted_docs
(Integer) Number of deleted documents in the segment, such as 0. This number is based on Lucene documents. Elasticsearch reclaims the disk space of deleted Lucene documents when a segment is merged.
size_in_bytes
(Integer) Disk space used by the segment, such as 50kb.
memory_in_bytes

(Integer) Bytes of segment data stored in memory for efficient search, such as 1264.

A value of -1 indicates Elasticsearch was unable to compute this number.

committed

(Boolean) If true, the segments is synced to disk. Segments that are synced can survive a hard reboot.

If false, the data from uncommitted segments is also stored in the transaction log so that Elasticsearch is able to replay changes on the next start.

search

(Boolean) If true, the segment is searchable.

If false, the segment has most likely been written to disk but needs a refresh to be searchable.

version
(String) Version of Lucene used to write the segment.
compound
(Boolean) If true, Lucene merged all files from the segment into a single file to save file descriptors.
attributes
(Object) Contains information about whether high compression was enabled.

Examplesedit

Get segment information for a specific indexedit

GET /test/_segments

Get segment information for several indicesedit

GET /test1,test2/_segments

Get segment information for all indicesedit

GET /_segments

The API returns the following response:

{
  "_shards": ...
  "indices": {
    "test": {
      "shards": {
        "0": [
          {
            "routing": {
              "state": "STARTED",
              "primary": true,
              "node": "zDC_RorJQCao9xf9pg3Fvw"
            },
            "num_committed_segments": 0,
            "num_search_segments": 1,
            "segments": {
              "_0": {
                "generation": 0,
                "num_docs": 1,
                "deleted_docs": 0,
                "size_in_bytes": 3800,
                "memory_in_bytes": 1410,
                "committed": false,
                "search": true,
                "version": "7.0.0",
                "compound": true,
                "attributes": {
                }
              }
            }
          }
        ]
      }
    }
  }
}

Verbose modeedit

To add additional information that can be used for debugging, use the verbose flag.

This functionality is experimental and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features.

GET /test/_segments?verbose=true

The API returns the following response:

{
    ...
        "_0": {
            ...
            "ram_tree": [
                {
                    "description": "postings [PerFieldPostings(format=1)]",
                    "size_in_bytes": 2696,
                    "children": [
                        {
                            "description": "format 'Lucene50_0' ...",
                            "size_in_bytes": 2608,
                            "children" :[ ... ]
                        },
                        ...
                    ]
                },
                ...
                ]

        }
    ...
}