# Nested JSON in CSV

**URL:** https://discuss.elastic.co/t/nested-json-in-csv/346310
**Category:** Elasticsearch
**Created:** [November 2, 2023, 4:17pm UTC](https://discuss.elastic.co/t/nested-json-in-csv/346310 "2023-11-02T16:17:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Cal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cal/32/127008_2.png) [@Cal](https://discuss.elastic.co/u/Cal)
#### Post date: [November 2, 2023, 4:17pm UTC](https://discuss.elastic.co/t/nested-json-in-csv/346310/1 "2023-11-02T16:17:41Z")

</div>

I have a CSV file with 1500 rows of data. I am wanting to optimize how I have certain data and nest it in Elastic.

Here's an example:

Name, Location, Age, Favorite Colors  
Bob, USA, 32, Orange, Pink  
Jane, USA, 28, Green, Pink

Currently "Orange, Pink" and "Green, Pink" will be displayed as two documents. If I visualize this data, it will show as "Orange, Pink" and "Green, Pink" when what I would want to see is Orange, Green, and two counts of Pink.

I want to Nest this data so that it looks more like:  
Name, Location, Age, Favorite Colors  
Bob, USA, 32, Orange  
........................ Pink

I'm having trouble finding the right documentation for how to write this into a CSV. I've read you can put JSON nesting into a cell in a CSV but I can't seem to figure out how it's formatting. I'm getting conflicting info that it needs to be a true array or if it can be a single line.

When I try to import nested data with nested mapping, no data imports at all, even for the columns that just have keywords like "Bob."

---

<div class="post-metadata">

### Author: ![Quentin\_Pradet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/quentin_pradet/32/94192_2.png) [@Quentin\_Pradet](https://discuss.elastic.co/u/Quentin_Pradet)
#### Post date: [November 3, 2023, 4:54am UTC](https://discuss.elastic.co/t/nested-json-in-csv/346310/2 "2023-11-03T04:54:39Z")

</div>

Hello!

The CSV format does not have a concept of arrays so you won't be able to do what you want using only CSV. Thinking out loud, here are ways to fix your problem:

- Convert your CSV to JSON, turning "Favorite Colors" into an array
- Write code using one of the Elasticsearch clients to turn "Favorite Colors" in an array and bulks index the results
- Use Logstash and its split filter: [Split filter plugin | Logstash Reference [8.10] | Elastic](https://www.elastic.co/guide/en/logstash/current/plugins-filters-split.html)
- I was going to suggest ingest pipelines but they don't support this: [[Ingest Pipeline] Ability to split documents · Issue #56769 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/56769)

---

<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: [December 1, 2023, 4:55am UTC](https://discuss.elastic.co/t/nested-json-in-csv/346310/3 "2023-12-01T04:55:26Z")

</div>

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