# Compare common value in 2 documents within a index and create a field in documents

**URL:** <https://discuss.elastic.co/t/compare-common-value-in-2-documents-within-a-index-and-create-a-field-in-documents/237620>\
**Category:** Kibana\
**Created:** [June 18, 2020, 10:56am UTC](https://discuss.elastic.co/t/compare-common-value-in-2-documents-within-a-index-and-create-a-field-in-documents/237620 "2020-06-18T10:56:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vishnu\_G](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vishnu_g/32/46948_2.png) [@Vishnu\_G](https://discuss.elastic.co/u/Vishnu_G)\
**Post date:** [June 18, 2020, 10:56am UTC](https://discuss.elastic.co/t/compare-common-value-in-2-documents-within-a-index-and-create-a-field-in-documents/237620/1 "2020-06-18T10:56:49Z")

</div>

`I have metricbeats configured to send process and services metrics to kibana. `

`Process and windows services have a common field i.e., pid . My requirement is to create a TSVB that will show memory utilization of all windows services. But unfortunately, utilization related metrics are exported from process module but not windows module. `

`So, I thought of creating a new scripted field that will compare common pid value in both process documents with service documents and create a field "Name_From_Service" with windows.service.name field from services document. `

`I don't have idea on painless script to create this field. Kindly help me with this. Thanks in advance. `

---

<div class="post-metadata">

**Author:** ![mattkime](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattkime/32/43522_2.png) [@mattkime](https://discuss.elastic.co/u/mattkime)\
**Post date:** [June 25, 2020, 1:43am UTC](https://discuss.elastic.co/t/compare-common-value-in-2-documents-within-a-index-and-create-a-field-in-documents/237620/2 "2020-06-25T01:43:19Z")

</div>

You should take a look at `Painless Lab` inside of `Dev Tools`.

Further info - [https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-walkthrough.html](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-walkthrough.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 23, 2020, 1:43am UTC](https://discuss.elastic.co/t/compare-common-value-in-2-documents-within-a-index-and-create-a-field-in-documents/237620/3 "2020-07-23T01:43:20Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
