Two things. Elasticsearch builds an inverted index out of that basically, the inverted index part will contain something like:
Type-A: 1, 2
Where 1 and 2 are the documents id. That's schematic as other things are also added.
But, elasticsearch will also add a stored field named _source
which will contain:
{"name":"first","class": "Type-A"}
And
{"name":"second","class": "Type-A"}
As is. But this is compressed by default.
Normally, you don't really have to think about all this.
Do ES optimize this somehow?
As yes, ES optimized as much as possible all that.