# How to add field that is only present in some documents?

**URL:** <https://discuss.elastic.co/t/how-to-add-field-that-is-only-present-in-some-documents/295283>\
**Category:** Kibana\
**Tags:** transforms\
**Created:** [January 24, 2022, 8:40pm UTC](https://discuss.elastic.co/t/how-to-add-field-that-is-only-present-in-some-documents/295283 "2022-01-24T20:40:28Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![przemekwitek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/przemekwitek/32/79526_2.png) [@przemekwitek](https://discuss.elastic.co/u/przemekwitek)\
**Post date:** [January 26, 2022, 12:30pm UTC](https://discuss.elastic.co/t/how-to-add-field-that-is-only-present-in-some-documents/295283/8 "2022-01-26T12:30:47Z")

</div>

IMO there are 2 more features that you should take into account when designing your solution:

1. specify `person` in the `group_by` clause and set `missing_bucket` to `true` so that the buckets **without** a `person` field are also returned

You can read more about `missing_bucket` in the docs: [Composite aggregation | Reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-composite-aggregation.html#_missing_bucket)

1. specify `person` in the `aggregations` clause but use `top_metrics` aggregation instead of `terms`.

You can read more about `top_metrics` in this blog:

> [@Dec 11th, 2021: \[en\] On a road trip with Transform](https://discuss.elastic.co/t/dec-11th-2021-en-on-a-road-trip-with-transform/290532):
>
> Are you already tired of hearing Christmas songs? One of the classics is "Driving home for Christmas". The lyrics of that song have not much content, Chris Rea basically tells about a long boring journey in his car driving home. In this post we accompany this song and spice it with new bits and pieces about [Transforms](https://www.elastic.co/guide/en/elasticsearch/reference/current/transforms.html). Transforms provide an easy way to summarize data. And it's been so long The aim of a search engine - like Elasticsearch - is to provide relevant results quickly. For your family…

---

_[View the full topic](https://discuss.elastic.co/t/how-to-add-field-that-is-only-present-in-some-documents/295283)._
