# Why does split creates multiple output records in json filter

**URL:** <https://discuss.elastic.co/t/why-does-split-creates-multiple-output-records-in-json-filter/233490>\
**Category:** Logstash\
**Created:** [May 20, 2020, 8:35am UTC](https://discuss.elastic.co/t/why-does-split-creates-multiple-output-records-in-json-filter/233490 "2020-05-20T08:35:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ullas7](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ullas7/32/68349_2.png) [@Ullas7](https://discuss.elastic.co/u/Ullas7)\
**Post date:** [May 20, 2020, 8:35am UTC](https://discuss.elastic.co/t/why-does-split-creates-multiple-output-records-in-json-filter/233490/1 "2020-05-20T08:35:02Z")

</div>

I havea JSON with array element in it

```auto
{
   "K1": "V1",
    "k2":"v2",
    "k3": [{"a1":"b1","a2":"b2"},{"a1":"c1","a2":d2}]
}

```

After logstash filter, I saving this in Elastic search, but for single json record its inserting two records

```auto
Record -1
{
    "id":1,
    "K1": "V1",
    "k2":"v2",
    "a1":"b1",
    "a2":"b2" 
}

Record -2
{
   "id":2,
   "K1": "V1",
   "k2":"v2",
   "a1":"c1",
   "a2":"d2" 
}

```

Expected :

```auto
{
   "id":1,
   "K1": "V1",
   "k2":"v2",
   "a1.0":"b1",
    "a2.0":"b2" 
   "a1.1":"c1",
   "a2.1":"d2" 
}

```

I tried making key unique thinking this causing the issue, but still, it created two records. Fundamentally I want to understand what is causing two record creation, I assume its split filter. Please help me in understanding. I will share my config if required.

---

<div class="post-metadata">

**Author:** ![andres-perez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andres-perez/32/136461_2.png) [@andres-perez](https://discuss.elastic.co/u/andres-perez)\
**Post date:** [May 20, 2020, 3:56pm UTC](https://discuss.elastic.co/t/why-does-split-creates-multiple-output-records-in-json-filter/233490/2 "2020-05-20T15:56:41Z")

</div>

Hi,

That is the expected behavior of [split filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-split.html#_description_146), split the original document into several ones, so unfortunately is not useful for your use case.

I'm not 100% sure about your expected output, either new fields with the original + period "." + correlative index, like "a1.0" or an array of elements "a1" : ["b1" , "c1"].  
¿Can you clarify this?

I think the most straightforward way to do it would be with a ruby filter with custom code to process the original array and create these fields.

---

<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:** [June 17, 2020, 3:56pm UTC](https://discuss.elastic.co/t/why-does-split-creates-multiple-output-records-in-json-filter/233490/3 "2020-06-17T15:56:48Z")

</div>

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