# Nested Objects in Elastic

**URL:** <https://discuss.elastic.co/t/nested-objects-in-elastic/236321>\
**Category:** Elasticsearch\
**Created:** [June 9, 2020, 11:21am UTC](https://discuss.elastic.co/t/nested-objects-in-elastic/236321 "2020-06-09T11:21:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayyappa\_P](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ayyappa_p/32/59015_2.png) [@Ayyappa\_P](https://discuss.elastic.co/u/Ayyappa_P)\
**Post date:** [June 9, 2020, 11:21am UTC](https://discuss.elastic.co/t/nested-objects-in-elastic/236321/1 "2020-06-09T11:21:39Z")

</div>

Hi, I have a data in the following format. I'm trying with ELastic 7.6 and using Kibana.

```auto
{"l1f1":"f1Value","l1f2":[{"l2f1":"l1f1Value","l2f2":"l2f2Value","l2f3":"l2f3Value"}]}

```

I want to index this data using bulk insert operation. My Index creation script is

```auto
 {
	"settings": {
		"analysis": {
			"analyzer": {
				"Custom_Casing_Analyzer": {
					"type": "custom",
					"tokenizer": "keyword",
					"filter": [
						"lowercase","uppercase"
					]
				}
			}
		}
	},
	"mappings":{ "properties": { "l1f2":{"type": "nested"} }}
}

```

I want that l1f2 field to be nested. but I'm getting the following error

`{"took":6,"errors":true,"items":[{"index":{"_index":"dummy1","_type":"dummy1","_id":"f1Value","status":400,"error":{"type":"illegal_argument_exception","reason":"object mapping [l1f2] can't be changed from nested to non-nested"}}}`

Can you tell me what should be the proper approach for this?

@dadoonet can you help. I have tried your solution in the link [Index Mapping Issue - Getting Error: "reason" : "object mapping [locations] can't be changed from nested to non-nested"](https://discuss.elastic.co/t/index-mapping-issue-getting-error-reason-object-mapping-locations-cant-be-changed-from-nested-to-non-nested/227938) But I'm using Elastic 7.6, so that solution didn't worked.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 9, 2020, 2:12pm UTC](https://discuss.elastic.co/t/nested-objects-in-elastic/236321/2 "2020-06-09T14:12:45Z")

</div>

I tried this (7.7.1):

```auto
DELETE test 
PUT test
{
  "mappings": {
    "properties": {
      "l1f2": {
        "type": "nested"
      }
    }
  }
}
POST test/_doc
{
  "l1f1": "f1Value",
  "l1f2": [
    {
      "l2f1": "l1f1Value",
      "l2f2": "l2f2Value",
      "l2f3": "l2f3Value"
    }
  ]
}

```

This worked well:

```auto
{
  "_index" : "test",
  "_type" : "_doc",
  "_id" : "-JNsmXIBwdOO0y9Zttmx",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

```

---

<div class="post-metadata">

**Author:** ![Ayyappa\_P](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ayyappa_p/32/59015_2.png) [@Ayyappa\_P](https://discuss.elastic.co/u/Ayyappa_P)\
**Post date:** [June 15, 2020, 4:15am UTC](https://discuss.elastic.co/t/nested-objects-in-elastic/236321/3 "2020-06-15T04:15:00Z")

</div>

Hi @dadoonet , This Worked well, The Mistake I have done in the above is not assigning the "\_doc" while adding the data.  
Previously it used to be the type name.  
What is the significance of this "\_doc"  
Can you help me with any tutorials on Latest Elastic Integration with C#?

Thanks,  
Ayyappa

---

<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 13, 2020, 4:15am UTC](https://discuss.elastic.co/t/nested-objects-in-elastic/236321/4 "2020-07-13T04:15:02Z")

</div>

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