You can use Source Filtering feature to exclude _source (object/nested data) in elasticsearch query results. This examples excludes child _source object completely.


Mapping


As you can see below, 1 parent product document can have many child tags documents in it.


{
"product_idx": {
"mappings": {
"product": {
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "text"
},
"tags": {
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "text"
}
}
}
}
}
}
}
}

Including tags


curl -XPOST 'http://localhost:9200/product_idx/_search' -d '{
"query": {
"term": {
"id": 1
}
}
}'

# Result
{
"hits": {
"hits": [
{
"_index": "product_idx",
"_type": "product",
"_id": "1",
"_score": 1,
"_source": {
"id": 1,
"name": "Phone",
"tags": [
{
"id": 1,
"name": "T1"
},
{
"id": 2,
"name": "T2"
}
]
}
}
]
}
}

Excluding tags


curl -XPOST 'http://localhost:9200/product_idx/_search' -d '{
"query": {
"term": {
"id": 1
}
},
"_source": {
"excludes": [
"tags"
]
}
}'

# Result
{
"hits": {
"hits": [
{
"_index": "product_idx",
"_type": "product",
"_id": "1",
"_score": 1,
"_source": {
"id": 1,
"name": "Phone"
}
}
]
}
}