# Merge data from several csv sources

**URL:** <https://discuss.elastic.co/t/merge-data-from-several-csv-sources/259381>\
**Category:** Logstash\
**Created:** [December 22, 2020, 12:35pm UTC](https://discuss.elastic.co/t/merge-data-from-several-csv-sources/259381 "2020-12-22T12:35:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MickD](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@MickD](https://discuss.elastic.co/u/MickD)\
**Post date:** [December 22, 2020, 12:35pm UTC](https://discuss.elastic.co/t/merge-data-from-several-csv-sources/259381/1 "2020-12-22T12:35:26Z")

</div>

Hello,

I'm new to ELK so please apologies if my question is trivial.

I have 3 CSV files with data that I would like to merge.  
In each file, each row represent a data which can be father or child of a row in another file(s).

I would like to be able to create a "single" merged object to be send to elastic ( some fields can be null if there is no link between datas)

Note that each file might have field with same names and I should rename it in the result one. I also must do some field addition with date comparison.

_MyData_ :  
A.id | B.id | C.id | A. startDate | A.endDate | A.diff | B.startDate | B.endDate | B.diff| ......

I currently succeed to parse one file but I do not found any tips on internet for my need.

My current file content

```
input {
    file {
            type => "LevelA"
            path => "D:/LevelA.txt"
            start_position => "beginning"
            sincedb_path => "NUL"
        }
      file {
            type => "LevelB"
            path => "D:/LevelB.txt"
            start_position => "beginning"
            sincedb_path => "NUL"
        }
      file {
            type => "LevelC"
            path => "D:/LevelC.txt"
            start_position => "beginning"
            sincedb_path => "NUL"
        }
}
filter {
    csv {
        separator => ","
        skip_header => "true"
        columns => ["id","startDate", "endDate","msg"]
    }

}
output {
  elasticsearch {
      hosts => ["localhost:9200"]
      index => "mydata"
  }
    stdout {codec => rubydebug}
 }
```

---

<div class="post-metadata">

**Author:** ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)\
**Post date:** [December 22, 2020, 1:52pm UTC](https://discuss.elastic.co/t/merge-data-from-several-csv-sources/259381/2 "2020-12-22T13:52:05Z")

</div>

How you define the unique recod (The parent) from the 3 files ? using only id or a combination of id and startDate ?

---

<div class="post-metadata">

**Author:** ![MickD](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@MickD](https://discuss.elastic.co/u/MickD)\
**Post date:** [December 22, 2020, 1:57pm UTC](https://discuss.elastic.co/t/merge-data-from-several-csv-sources/259381/3 "2020-12-22T13:57:51Z")

</div>

There is a field which handle this ( not set in my exemple ) : child.id to link items between them.

Therefore the "unique record" is a combinaison between the 3 "first ids" which be

X | Y | Z  
or  
N.A | N.A| Z ( and all possible combination )

What is not possible is to have the same ID for the 3 (ie X | X | X )

---

<div class="post-metadata">

**Author:** ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)\
**Post date:** [December 22, 2020, 2:04pm UTC](https://discuss.elastic.co/t/merge-data-from-several-csv-sources/259381/4 "2020-12-22T14:04:20Z")

</div>

Could you share a real example of the 3 files ?

---

<div class="post-metadata">

**Author:** ![MickD](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@MickD](https://discuss.elastic.co/u/MickD)\
**Post date:** [December 22, 2020, 3:16pm UTC](https://discuss.elastic.co/t/merge-data-from-several-csv-sources/259381/5 "2020-12-22T15:16:36Z")

</div>

Not the "real" ones but I can simplify them...

High Level

> id,Creation\_Date,Children.id,  
> ID\_07946,12/11/2020 15:53,ID\_06172

MidLevel

> id,Creation\_Date,Children.id  
> ID\_06172,17/06/2020 18:55,ID\_06654  
> ID\_07321,14/01/2020 04:00,ID\_09054

Low Level

> id,Creation\_Date  
> ID\_06654,31/07/2020 11:24  
> ID\_09054,30/04/2020 15:50  
> ID\_04044, 24/04/2020 16:20

---

<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:** [January 19, 2021, 3:16pm UTC](https://discuss.elastic.co/t/merge-data-from-several-csv-sources/259381/6 "2021-01-19T15:16:39Z")

</div>

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