# Aligning array elements with parent in table visualization

**URL:** https://discuss.elastic.co/t/aligning-array-elements-with-parent-in-table-visualization/338962
**Category:** Kibana
**Created:** [July 21, 2023, 5:38pm UTC](https://discuss.elastic.co/t/aligning-array-elements-with-parent-in-table-visualization/338962 "2023-07-21T17:38:33Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Thomas.c](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@Thomas.c](https://discuss.elastic.co/u/Thomas.c)
#### Post date: [July 21, 2023, 5:38pm UTC](https://discuss.elastic.co/t/aligning-array-elements-with-parent-in-table-visualization/338962/1 "2023-07-21T17:38:33Z")

</div>

I'm trying to create a table visualization in Kibana. My data structure is like this:  
Vehicle{  
Vehicle Number  
Vehicle make  
Vehicle model  
Vehicle year}

Each record can have multiple vehicles in it, so the parent Vehicle data element is an array. The problem I have is that if I try to output the data into a table visualization, kibana combines each element with each possible other element, rather than only displaying information relevant to each vehicle. So, if I have one vehicle in the record, it works flawlessly. But then for records with multiple vehicles, I see duplication of data.

For example: a record has 2 vehicles in it. 2006 Toyota Corrola and 2010 Ford Taurus. I want to see the following table, two lines only.

Year Make Model  
2006 Toyota Corrola  
2010 Ford Taurus

But what I actually get is:  
Year Make Model  
2006 Toyota Corrola  
2006 Toyota Taurus  
2006 Ford Corrola  
2006 Ford Taurus  
2010 Toyota Corrola  
2010 Toyota Taurus  
2010 Ford Corrola  
2010 Ford Taurus

Does anybody know what I might need to do to get each line in the table to only show information relevant to the array it is part of? I have to imagine it's simple, I'm just not finding what it could be.

---

<div class="post-metadata">

### Author: ![PodarcisMuralis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/podarcismuralis/32/122606_2.png) [@PodarcisMuralis](https://discuss.elastic.co/u/PodarcisMuralis)
#### Post date: [July 22, 2023, 3:28pm UTC](https://discuss.elastic.co/t/aligning-array-elements-with-parent-in-table-visualization/338962/2 "2023-07-22T15:28:47Z")

</div>

Can you please check if the field type is mapped as "nested" in elasticsearch?

An example of nested mapping:

Using nested:

```auto
PUT /people_index
{
  "mappings": {
    "properties": {
      "name": { "type": "keyword" },
      "age": { "type": "integer" },
      "vehicles": {
        "type": "nested",
        "properties": {
          "vehicleNumber": { "type": "keyword" },
          "vehicleMake": { "type": "keyword" },
          "vehicleModel": { "type": "keyword" },
          "vehicleYear": { "type": "integer" }
        }
      }
    }
  }
}

```

Data indexed with nested:

```auto
POST /people_index/_doc/1
{
  "name": "John",
  "age": 30,
  "vehicles": [
    {
      "vehicleNumber": "ABC123",
      "vehicleMake": "Toyota",
      "vehicleModel": "Corolla",
      "vehicleYear": 2006
    },
    {
      "vehicleNumber": "XYZ789",
      "vehicleMake": "Ford",
      "vehicleModel": "Taurus",
      "vehicleYear": 2010
    }
  ]
}

```

Mapping without nested:

```auto
PUT /people_index
{
  "mappings": {
    "properties": {
      "name": { "type": "keyword" },
      "age": { "type": "integer" },
      "vehicles": {
        "type": "keyword"
      }
    }
  }
}

```

Data without nested:

```auto
POST /people_index/_doc/1
{
  "name": "John",
  "age": 30,
  "vehicles": ["ABC123", "Toyota", "Corolla", 2006, "XYZ789", "Ford", "Taurus", 2010]
}

```

I may be wrong but please give it a shot. Thanks.

---

<div class="post-metadata">

### Author: ![Thomas.c](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@Thomas.c](https://discuss.elastic.co/u/Thomas.c)
#### Post date: [July 24, 2023, 5:20pm UTC](https://discuss.elastic.co/t/aligning-array-elements-with-parent-in-table-visualization/338962/3 "2023-07-24T17:20:35Z")

</div>

Thanks so much for responding! There are a lot of extra fields so I'm just going to extract a couple fields from the vehicles, but it looks like this:

```auto
...
  "vehicles": [
	{
	  "vehicleNumber": 1,	
		"vehicleMake": {
		"name": "HONDA",
		"value": "HOND"
	  },
	  "vehicleColor": {
		"name": "White",
		"value": "WHI"
	  },
	  "vehicleModel": {
		"name": "CR-V",
		"value": "CRV"
	  }
	},
	{
	  "unitNumber": 2,
	  "vehicleMake": {
		"name": "HONDA",
		"value": "HOND"
	  },
	  "vehicleColor": {
		"name": "Blue/Light",
		"value": "LBL"
	  },
	  "vehicleModel": {
		"name": "RIDGELINE",
		"value": "RGL"
	  },
	}
  ], 
...

```

To me that looks like it's nested, BUT when I look at the mapping, the "nested" type isn't there. It looks like this (Only including the mapping for number and color, the rest are very similar, all key/value pairs):

```auto
{
  "mappings": {
    "properties": {
      "vehicles": {
        "properties": {
          "vehicleNumber": {
            "type": "long"
          },
          "vehicleColor": {
            "properties": {
              "name": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "value": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          },
		}
    }
  }
}

```

So in this case, should I just add a type before the vehicles properties? If so, am I going to need to re-index everything to accommodate that, or can it just understand that change with the current data?

---

<div class="post-metadata">

### Author: ![Thomas.c](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@Thomas.c](https://discuss.elastic.co/u/Thomas.c)
#### Post date: [July 25, 2023, 7:16pm UTC](https://discuss.elastic.co/t/aligning-array-elements-with-parent-in-table-visualization/338962/4 "2023-07-25T19:16:53Z")

</div>

I made the modification to the mapping such that vehicles is of type "nested" and the data seems to be there properly, but I don't see any of the fields within that nested array in the kibana visualization options. Is there a special way to access the children in that nested data structure?

---

<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: [August 22, 2023, 7:17pm UTC](https://discuss.elastic.co/t/aligning-array-elements-with-parent-in-table-visualization/338962/5 "2023-08-22T19:17:20Z")

</div>

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