Elasticsearch's search API supports a "fields" parameter to limit the fields returned from the hits. It supports dot notation for sub-properties of a document as well. For example, a query
{
"fields" : ["user.lastname"],
"query" : {
"term" : { "_id" : 1 }
}
}
will return hits as:
{
"hits": [
{"_id": 1,
"user.lastname": "Smith"}
]
}
I am wondering if there is an option to make it return as this instead:
{
"hits": [
{"_id": 1,
"user": {"lastname": "Smith"}}
]
}
The benefit of the second one is maintaining the same structure as the full document, as that the following data access logic is consistent.