# Add a new field to document based on the value of the previous with the same correlation id

**URL:** https://discuss.elastic.co/t/add-a-new-field-to-document-based-on-the-value-of-the-previous-with-the-same-correlation-id/96379
**Category:** Elasticsearch
**Created:** [August 9, 2017, 6:36am UTC](https://discuss.elastic.co/t/add-a-new-field-to-document-based-on-the-value-of-the-previous-with-the-same-correlation-id/96379 "2017-08-09T06:36:18Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![vb4t](https://avatars.discourse-cdn.com/v4/letter/v/a698b9/32.png) [@vb4t](https://discuss.elastic.co/u/vb4t)
#### Post date: [August 9, 2017, 6:36am UTC](https://discuss.elastic.co/t/add-a-new-field-to-document-based-on-the-value-of-the-previous-with-the-same-correlation-id/96379/1 "2017-08-09T06:36:18Z")

</div>

Hello. I want to index following logs in elasticsearch:

```
message1 correlation1 urlfield
message2 correlation6
message3 correlation1
message4 correlation1

```

I want documents message3 and message4 to contain the urlfield field of the first correlation1 (message1) document.  
How to do it? I can not use logstash because logs are balanced to multiple logstashes and are out of order so I probably must to do it somehow on elasticsearch site...

I use following components: elasticsearch, logstash, kibana.

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [August 9, 2017, 6:44am UTC](https://discuss.elastic.co/t/add-a-new-field-to-document-based-on-the-value-of-the-previous-with-the-same-correlation-id/96379/2 "2017-08-09T06:44:31Z")

</div>

Create an entity centric index.  
See [https://youtu.be/yBf7oeJKH2Y](https://youtu.be/yBf7oeJKH2Y)  
The comments section for the video has the link to example code and data

---

<div class="post-metadata">

### Author: ![vb4t](https://avatars.discourse-cdn.com/v4/letter/v/a698b9/32.png) [@vb4t](https://discuss.elastic.co/u/vb4t)
#### Post date: [August 9, 2017, 10:31am UTC](https://discuss.elastic.co/t/add-a-new-field-to-document-based-on-the-value-of-the-previous-with-the-same-correlation-id/96379/3 "2017-08-09T10:31:03Z")

</div>

Is it suitable for log management usage? I have just one index "filebeat-app" for for some app. I found logstash input elasticsearch - could I use it for this? filebeat-app is quite big (800G+) ...

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [August 9, 2017, 10:37am UTC](https://discuss.elastic.co/t/add-a-new-field-to-document-based-on-the-value-of-the-previous-with-the-same-correlation-id/96379/4 "2017-08-09T10:37:35Z")

</div>

> Is it suitable for log management usage?

You'd need to implement your own life-cycle management policies for entities. Logs are typically stored in time-based indices and retained for fixed periods but entities can span these time periods and need their own retention policy.  
You should adopt an incremental update approach to your entities based on latest changes in your event store (aka logs). [This thread](https://discuss.elastic.co/t/entity-centric-indexing-reliability-and-performance/93374) got into the specifics of how to implement a robust incremental update pipeline for entities.

---

<div class="post-metadata">

### Author: ![vb4t](https://avatars.discourse-cdn.com/v4/letter/v/a698b9/32.png) [@vb4t](https://discuss.elastic.co/u/vb4t)
#### Post date: [August 9, 2017, 11:27am UTC](https://discuss.elastic.co/t/add-a-new-field-to-document-based-on-the-value-of-the-previous-with-the-same-correlation-id/96379/5 "2017-08-09T11:27:17Z")

</div>

OK. Got the principle. Is it required to do it with external scripts/tools? Or is it a good idea to implement it using losgstash elasticsearch input + filter or using watcher scheduler?

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [August 9, 2017, 11:36am UTC](https://discuss.elastic.co/t/add-a-new-field-to-document-based-on-the-value-of-the-previous-with-the-same-correlation-id/96379/6 "2017-08-09T11:36:40Z")

</div>

> or using watcher scheduler?

Watcher will rely on aggregations whose request/response interaction will put a memory limit on how much data on individual entities you can bring back from the event store. In contrast, the scroll api is a streaming interface and therefore allows you to process larger volumes of entity events.

You can piece the pull-and-push task together with whatever agent can use the `scroll` and `bulk` apis respectively to create the flow of data from event store to entity store. I used Python but that's not the only possible client.

However the in-place update of entity docs on the shards where they live is best done with a Painless script.

---

<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: [September 6, 2017, 11:36am UTC](https://discuss.elastic.co/t/add-a-new-field-to-document-based-on-the-value-of-the-previous-with-the-same-correlation-id/96379/7 "2017-09-06T11:36:50Z")

</div>

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