The reason you can't do doc['types']
is that there is not a field int he index called types
.
This might take a bit to explain so bear with me.
When you index a document with nested objects the document is split into multiple documents in the index, so if you index the following document:
PUT /my_index/blogpost/1
{
"title": "Nest eggs",
"body": "Making your money work...",
"tags": [ "cash", "shares" ],
"comments": [
{
"name": "John Smith",
"comment": "Great article",
"age": 28,
"stars": 4,
"date": "2014-09-01"
},
{
"name": "Alice White",
"comment": "More like this please",
"age": 31,
"stars": 5,
"date": "2014-10-22"
}
]
}
In the index it conceptually looks like this:
# First nested object
{
"comments.name": [ john, smith ],
"comments.comment": [ article, great ],
"comments.age": [ 28 ],
"comments.stars": [ 4 ],
"comments.date": [ 2014-09-01 ]
}
# Second nested object
{
"comments.name": [ alice, white ],
"comments.comment": [ like, more, please, this ],
"comments.age": [ 31 ],
"comments.stars": [ 5 ],
"comments.date": [ 2014-10-22 ]
}
# The root or parent document
{
"title": [ eggs, nest ],
"body": [ making, money, work, your ],
"tags": [ cash, shares ]
}
So the nested objects in comments
are split out into their own special documents which reside next to the root document. This is what makes nested operations work.
So as you can see, neither the root document or the nested documents have a field called comments
but the nested documents do have fields called comments.name
, comments.comment
, comments.age
etc.
In order to get the DocValues value for your nested documents you will need to use the specific fields inside your types
objects in your custom score script (i.e. doc['types.price']
or doc['status']
in your example doc above)
you can read more about nested objects in this section of the Elasticsearch: The Definitive Guide book: https://www.elastic.co/guide/en/elasticsearch/guide/2.x/nested-objects.html