# Index parent-child data from csv to elasticsearch

**URL:** https://discuss.elastic.co/t/index-parent-child-data-from-csv-to-elasticsearch/170035
**Category:** Logstash
**Created:** [February 26, 2019, 3:17pm UTC](https://discuss.elastic.co/t/index-parent-child-data-from-csv-to-elasticsearch/170035 "2019-02-26T15:17:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![chandan.sing1](https://avatars.discourse-cdn.com/v4/letter/c/a4c791/32.png) [@chandan.sing1](https://discuss.elastic.co/u/chandan.sing1)
#### Post date: [February 26, 2019, 3:17pm UTC](https://discuss.elastic.co/t/index-parent-child-data-from-csv-to-elasticsearch/170035/1 "2019-02-26T15:17:59Z")

</div>

Hi,

I have 2 csv files with 1 to many relationship. How would i index both the files in same index with relationship. So, that i can generate the deep dive visualisation in detail based on selection.

CSV 1 : customerID(123), "chandan", "xxxxx@gmail.com"  
CSV 2 : customerID(123), "productID(213)", "New product"  
customerID(123), "productID(321)", "old product"

My parent conf file is

```auto
input {
      file {
          path => ["C:/XXXXX/XXXX/OrderDetail_20190130173419.txt"]
          type => "orderDetail"
          start_position => "beginning"
		  ignore_older => 0
      }
}

filter {
    csv {
        columns => ["customer ID","name","email"]
        separator => "|"
        skip_header => "true"
		remove_field => ["host", "message", "path"]
    }	
	mutate {
		add_field => { "family" => "orderDetail"}
	}
	
	fingerprint {
		source => "customer ID"
		target => "[@metadata][fingerprint]"
		method => "MURMUR3"
	}
}

output {
	stdout { codec => rubydebug }
    elasticsearch {
		hosts => ["localhost:9200"]
		index => "test-%{+YYYY.MM.dd}"
		document_id => "%{[@metadata][fingerprint]}"
    }	
}

```

and Child conf file is

```auto
input {
      file {
          path => ["C:/XXXXXX/XXXXX/BCC_OFAP_Open_OrderActivities_20190130173419.txt"]
          type => "orderActivity"
          start_position => "beginning"
		  ignore_older => 0
      }
}

filter {
    csv {
        columns => ["customer ID","product ID","product Desc"]
        separator => "|"
        skip_header => "true"
		remove_field => ["host", "message", "path"]
    }	
	fingerprint {
		source => "customer ID"
		target => "[@metadata][fingerprint]"
		method => "MURMUR3"
	}
	mutate{
		add_field => { "['family']['name']" => "orderActivity"}
		add_field => { "['family']['parent']" => "%{[@metadata][fingerprint]}"}
	}
}

output {
	stdout { codec => rubydebug }
    elasticsearch {
		hosts => ["localhost:9200"]
		index => "test-%{+YYYY.MM.dd}"
		routing => "%{[@metadata][fingerprint]}"
    }	
}

```

With above files, i am getting total 3 entry in same index, instead it should create 1 entry with two array of product Details in same entry

---

<div class="post-metadata">

### Author: ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)
#### Post date: [February 28, 2019, 12:12pm UTC](https://discuss.elastic.co/t/index-parent-child-data-from-csv-to-elasticsearch/170035/2 "2019-02-28T12:12:31Z")

</div>

This is a lookup enrichment scenario. Your need is to enrich each order detail with the customer info.  
You might be able use the `translate` filter to do the lookup on the `BCC_OFAP_Open_OrderActivities_20190130173419.txt` file.  
There are two problems I can think of:

1. The name of the file seems to be dynamic or tied to a specific date and time.
2. The structure will need to change. The translate filter takes a two column CSV form key comma value where in your case the key is the customer id and the value needs to be the rest of the columns as `|` delimited. This will put the `|` delimited string as a value into a "target" field. You will then need to use the `csv` or `dissect` (faster, as the structure is well known and not likely to change on the fly like log/metrics data can) filter to parse this value.

Let us know how the files are generated and we can advise further.

---

<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: [March 28, 2019, 12:12pm UTC](https://discuss.elastic.co/t/index-parent-child-data-from-csv-to-elasticsearch/170035/3 "2019-03-28T12:12:33Z")

</div>

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