Empty field in document takes up space in elasticsearch?

Empty field in document takes up space in elasticsearch? For example, in the case below, the total amount of space used to store the document is the same in case A as in case B (assuming the "color" field is defined in the mapping).

Case A
    {"features":
      "price": 1,
      "colors":[]
    }

Case B
    {"features":
      "price": 1,
    }
      

Run codeHide result


+3


source to share


1 answer


If you keep the default settings, the original document is saved in the _ source field , there will be a difference since the original document of case A is larger than case B.

Otherwise, there should be no difference: for case A, no term is added to the index for the color field because it is empty.

You can use the _size field to see the size of the indexed source document, which is the size of the _source field:



POST stack
{
  "mappings":{
    "features":{
      "_size": {"enabled":true, "store":true},
      "properties":{
        "price":{
          "type":"byte"
        },
        "colors":{
          "type":"string"
        }
      }
    }
  }
}

PUT stack/features/1
{
  "price": 1
}

PUT stack/features/2
{
  "price": 1,
  "colors": []
}

POST stack/features/_search
{
  "fields": [
    "_size"
  ]
}

      

The last query will print this result, which shows that document 2 takes up more space than document 1:

{
   "took": 1,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 2,
      "max_score": 1,
      "hits": [
         {
            "_index": "stack",
            "_type": "features",
            "_id": "1",
            "_score": 1,
            "fields": {
               "_size": 16
            }
         },
         {
            "_index": "stack",
            "_type": "features",
            "_id": "2",
            "_score": 1,
            "fields": {
               "_size": 32
            }
         }
      ]
   }
}

      

+3


source







All Articles