# Mappings for Nested Objects

**URL:** <https://discuss.elastic.co/t/mappings-for-nested-objects/135878>\
**Category:** Elasticsearch\
**Created:** [June 14, 2018, 9:11am UTC](https://discuss.elastic.co/t/mappings-for-nested-objects/135878 "2018-06-14T09:11:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![drendell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drendell/32/32263_2.png) [@drendell](https://discuss.elastic.co/u/drendell)\
**Post date:** [June 14, 2018, 9:11am UTC](https://discuss.elastic.co/t/mappings-for-nested-objects/135878/1 "2018-06-14T09:11:35Z")

</div>

Hi all,

I'm having trouble building out a suitable mapping structure that will appropriately accommodate nested objects.

ES and Kibana are both the latest versions.

Here's a truncated example (I've trimmed the two nested blocks down to reasonable sizes):

```
{  
   "id":12345,
   "label":"A string of text",
   "published_by":"some user id",
   "is_published":"boolean",
   "last_published":"2018-06-14",
   "first_published":"2018-06-14",
   "brand":"A keyword",
   "language":"ISO country code",
   "sender_ips":[  
      {  
         "ip":"1.2.3.4",
         "country":"England",
         "city":"London"
      },
      {  
         "ip":"1.2.1.2",
         "country":"Germany",
         "city":"Ravensburg"
      },
      {  
         "ip":"1.2.3.1",
         "country":"United States",
         "city":"West Lafayette"
      }
   ],
   "block_data":[  
      {  
         "data":"A Keyword",
         "impact":"A Keyword",
         "family":"A Keyword",
         "phenotype":"A keyword"
      },
      {  
         "data":"A Keyword",
         "impact":"A Keyword",
         "family":"A Keyword",
         "phenotype":"A keyword"
      },
      {  
         "data":"A Keyword",
         "impact":"A Keyword",
         "family":"A Keyword",
         "phenotype":"A keyword"
      }
        ],
   "m_ids":[  
      111111111,
      222222222,
      333333333
   ]
}

```

The mappings I'm currently using:

```
{
  "mappings": {
    "_doc": {
      "properties": {
        "id": {"type": "keyword"},
        "label": {"type": "text"},
		"published_by": {"type": "keyword"},
		"is_published": {"type": "boolean"},
		"first_published": {"type": "date"},
		"last_published": {"type": "date"},
		"brand": {"type": "keyword"},
		"language": {"type": "keyword"},
		"block_data": {
			"type": "nested",
			"properties": {
				"data": {"type": "keyword"},
				"impact": {"type": "keyword"},
				"family": {"type": "keyword"},
				"phenotype": {"type": "keyword"}
			}
			
		},
		"sender_ips": {
			"type": "nested",
			"properties": {
				"ip": {"type": "ip"},
				"country": {"type": "keyword"},
				"city": {"type": "keyword"}
			}			
		},
		"m_id": {"type": "text"}		
      }
    }
  }
}

```

The challenge I have, is that the sender\_ips fields do not populate (the block\_data fields seem to work fine).

![image](https://us1.discourse-cdn.com/elastic/original/3X/6/8/680ea95a28a8ba57c18d425864c27a83147500f1.png)

Kibana explicitly warns that nested objects are not well supported:

![image](https://us1.discourse-cdn.com/elastic/original/3X/e/f/efc6159a2bb0285f6c6568f3ebcf78ffab1cbd02.png)

Am I approaching this incorrectly? Is there a better way to think about storing these types of objects?

Cheers, for any help!

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [June 22, 2018, 9:44am UTC](https://discuss.elastic.co/t/mappings-for-nested-objects/135878/2 "2018-06-22T09:44:23Z")

</div>

"Nested" is only required if:

1. you need to test \>1 property of an object in a query or,
2. you need to count the number of nested objects rather than the number of root level docs

An example of problem 1) is if your queries are looking for `city:Paris AND country:France` - if you don't use nested then you could mistakenly match a doc that includes these 2 IP objects:

```
[{ city:Lyon, country:France}, {city:Paris, country:US}]

```

So Paris, Texas would match here because of what we call "cross-matching".  
If you only ever query for a single attribute eg `city:France` then there is no problem and you can avoid the need for nested.

---

<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:** [July 20, 2018, 9:44am UTC](https://discuss.elastic.co/t/mappings-for-nested-objects/135878/3 "2018-07-20T09:44:24Z")

</div>

Closed on July 20, 2018, 9:44am UTC

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