Link Search Menu Expand Document Documentation Menu

You're viewing version 2.16 of the OpenSearch documentation. This version is no longer maintained. For the latest version, see the current documentation. For information about OpenSearch version maintenance, see Release Schedule and Maintenance Policy.

Mapper-size plugin

The mapper-size plugin enables the use of the _size field in OpenSearch indexes. The _size field stores the size, in bytes, of each document.

Installing the plugin

You can install the mapper-size plugin using the following command:

./bin/opensearch-plugin install mapper-size

Examples

After starting up a cluster, you can create an index with size mapping enabled, index a document, and search for documents, as shown in the following examples.

Create an index with size mapping enabled

curl -XPUT example-index -H "Content-Type: application/json" -d '{
  "mappings": {
    "_size": {
      "enabled": true
    },
    "properties": {
      "name": {
        "type": "text"
      },
      "age": {
        "type": "integer"
      }
    }
  }
}'

Index a document

curl -XPOST example-index/_doc -H "Content-Type: application/json" -d '{
  "name": "John Doe",
  "age": 30
}'

Query the index

curl -XGET example-index/_search -H "Content-Type: application/json" -d '{
  "query": {
    "match_all": {}
  },
  "stored_fields": ["_size", "_source"]
}'

Query results

In the following example, the _size field is included in the query results and shows the size, in bytes, of the indexed document:

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1.0,
    "hits": [
      {
        "_index": "example_index",
        "_id": "Pctw0I8BLto8I5f_NLKK",
        "_score": 1.0,
        "_size": 37,
        "_source": {
          "name": "John Doe",
          "age": 30
        }
      }
    ]
  }
}
350 characters left

Have a question? .

Want to contribute? or .