How to find size of the document using scripting

I'm using ES 6.3, I want to find size of a document using script.
I've tried:
"script": "doc.toString().length()"
But doc.toString() is classname org.elasticsearch.search.lookup.LeafDocLookup@57b1c349.

I know I can enable _size by using size-mapper plugin, but don't have access to that, but scripting is enabled, so how can I do this?

Can you explain, what you are trying to achieve? You could try using a script ingest processor and just take the length of the toString() representation of the ctx map, however this would not be accurate, as it is not the original JSON.

Interested in the use-case here.

--Alex

@spinscale, I want to know total size of raw documents per day in the index. If I had the _size enabled I would do search query like:

{
  "size": 0,
  "aggs" : {
    "size_per_day" : {
        "date_histogram" : {
            "field" : "@timestamp",
            "interval" : "day"
        },
        "aggs": {
            "size": {
                "sum": {
                    "field": "_size" # Want to use script to find size
                }
            }
        }
    }
  }
}

Also I can't use index stats as it will have the compressed size. Please let me know If there is any other way.

Thanks,
RIddhesh

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.