Elasticsearch sorgu sonucundan istediğimiz _source (object/nested data) bilgilerini çıkarabilmemiz için Source Filtering özelliğini sunar. Bu örnek alt _source girdisini tamamen sonuç dışı bırakır.


Konfigürasyon


Aşağıda'da gördüğümüz gibi 1 ana product dökümanı birden fazla alt tags dökümanına sahip olabilir.


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

Tags'ın eklenmesi


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"
}
]
}
}
]
}
}

Tags'ın çıkarılması


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"
}
}
]
}
}