# Nested issue

**URL:** <https://discuss.elastic.co/t/nested-issue/49407>\
**Category:** Elasticsearch\
**Created:** [May 6, 2016, 12:46pm UTC](https://discuss.elastic.co/t/nested-issue/49407 "2016-05-06T12:46:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dominique](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dominique/32/9637_2.png) [@Dominique](https://discuss.elastic.co/u/Dominique)\
**Post date:** [May 6, 2016, 12:46pm UTC](https://discuss.elastic.co/t/nested-issue/49407/1 "2016-05-06T12:46:50Z")

</div>

Hi,

I have a little issue to use nested field in the mapping. I use elasticsearch 2.3.2

The mapping is the following:  
"@stk": {  
"properties": {  
" **@children**": {  
"type" : " **nested**",  
"properties": {  
"@name": {  
"type": "string",  
"index": "not\_analyzed"  
},  
" **@children**": {  
"type" : " **nested**",  
"properties": {  
"@name": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}....

Each children can have children up to 6 levels.

The data to insert is like :  
"@stk":{"@name":"Root","@time":5,  
" **@children**":[  
{"@name":"child1","@time":5,  
" **@children**":[  
{"@name":"child1.1","@time":3},  
{"@name":"child1.2","@time":2}  
]  
}  
]}

The insertion error is "error"=\>{"type"=\>"illegal\_argument\_exception", "reason"=\>"object mapping [@stk.@children] can't be changed from nested to non-nested"}

"type" : "object" works, but it's the nested type that I need for the queries.

Could you please kindly tell me what I do wrong ?

Thanks for your support,  
Dominique

---

<div class="post-metadata">

**Author:** ![Dominique](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dominique/32/9637_2.png) [@Dominique](https://discuss.elastic.co/u/Dominique)\
**Post date:** [May 18, 2016, 10:58am UTC](https://discuss.elastic.co/t/nested-issue/49407/2 "2016-05-18T10:58:42Z")

</div>

No one else has the same issue ?

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [May 18, 2016, 11:43am UTC](https://discuss.elastic.co/t/nested-issue/49407/3 "2016-05-18T11:43:57Z")

</div>

This means that there is already a mapping for the `children` field of type  
object. A field's type can't be changed after it is created. You should  
create a new index wit you mapping that uses nested fields and reindex your  
data from the current index into the new index.

---

<div class="post-metadata">

**Author:** ![Dominique](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dominique/32/9637_2.png) [@Dominique](https://discuss.elastic.co/u/Dominique)\
**Post date:** [May 18, 2016, 11:58am UTC](https://discuss.elastic.co/t/nested-issue/49407/4 "2016-05-18T11:58:52Z")

</div>

I have deleted and created again the index, so it should not have any data inside. And I still have the issue. I even change the name of the "children" in case it interferes with the other index.

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [May 18, 2016, 12:45pm UTC](https://discuss.elastic.co/t/nested-issue/49407/5 "2016-05-18T12:45:08Z")

</div>

Can you share the rest calls that you executed?

---

<div class="post-metadata">

**Author:** ![Dominique](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dominique/32/9637_2.png) [@Dominique](https://discuss.elastic.co/u/Dominique)\
**Post date:** [May 19, 2016, 5:49am UTC](https://discuss.elastic.co/t/nested-issue/49407/6 "2016-05-19T05:49:24Z")

</div>

Hi,  
Thansk for you answer.  
Below what I do.

curl -XDELETE '[http://myserver:9200/myindex](http://myserver:9200/myindex)'  
curl -XPUT '[http://myserver:9200/\_template/myindex](http://myserver:9200/_template/myindex)' -d '  
{  
"template": "myindex",  
"settings": {  
"number\_of\_shards": 1,  
"number\_of\_replicas": 2,  
"index.refresh\_interval": "5s"  
},  
"mappings": {  
"logs":  
{  
"properties": {  
"timestampGMT": {  
"type": "date",  
"format": "yyyy/MM/dd HH:mm:ss.SSSSSS"  
},  
"@stk": {  
"properties": {  
"@name": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"@totalTime": { "type": "double"},  
"@children": {  
"type" : "nested",  
"include\_in\_parent" : true,  
"properties": {  
"@name": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"@totalTime": { "type": "double"},  
"@children": {  
"type" : "nested",  
"include\_in\_parent" : true,  
"properties": {  
"@name": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"@totalTime": { "type": "double"}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}'

I try to insert  
{"@thr":0,"@customData":{"Data1":"1"},"@stk":{"@name":"Root","@totalTime":10,"@children":[{"@name":"SubRoot","@totalTime":10,"@children":[{"@name":"child1","@totalTime":5.5},{"@name":"child2","@totalTime":3.5},{"@name":"child3","@totalTime":1}]}]}}

And I get:  
..."@stk"=\>{"@name"=\>"Root", "@totalTime"=\>10, "@children"=\>[{"@name"=\>"SubRoot", "@totalTime"=\>10, "@children"=\>[{"@name"=\>"child1", "@totalTime"=\>#BigDecimal:2e0b1dd8,'0.55E1',2(4)}, {"@name"=\>"child2", "@totalTime"=\>#BigDecimal:724f9710,'0.35E1',2(4)}, {"@name"=\>"child3", "@totalTime"=\>1}]}]}}, "@stk"]}\>\>], :response=\>{"create"=\>{"\_index"=\>"myindex", "\_type"=\>"request1", "\_id"=\>"AVTHiW4YIkqJinos0jHU", "status"=\>400, "error"=\>{"type"=\>"illegal\_argument\_exception", "reason"=\>"object mapping [@stk.@children] can't be changed from nested to non-nested"}}}, :level=\>:warn}

What do I perform wrong ?

Thanks.

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [May 19, 2016, 8:42am UTC](https://discuss.elastic.co/t/nested-issue/49407/7 "2016-05-19T08:42:07Z")

</div>

I'm able to index the document using your reproduction. Are you sure that you are sending the index call to the right cluster?

These are the commands that I executed:

- Delete index: `curl -XDELETE "http://localhost:9200/myindex"`
- Put index template (I only changed `settings.number_of_replicas` to `0`, so that I don't need two nodes when indexing) :

```auto
curl -XPUT "http://localhost:9200/_template/myindex" -d'
{
  "template": "myindex",
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0,
    "index.refresh_interval": "5s"
  },
  "mappings": {
    "logs": {
      "properties": {
        "timestampGMT": {
          "type": "date",
          "format": "yyyy/MM/dd HH:mm:ss.SSSSSS"
        },
        "@stk": {
          "properties": {
            "@name": {
              "type": "string",
              "index": "not_analyzed"
            },
            "@totalTime": {
              "type": "double"
            },
            "@children": {
              "type": "nested",
              "include_in_parent": true,
              "properties": {
                "@name": {
                  "type": "string",
                  "index": "not_analyzed"
                },
                "@totalTime": {
                  "type": "double"
                },
                "@children": {
                  "type": "nested",
                  "include_in_parent": true,
                  "properties": {
                    "@name": {
                      "type": "string",
                      "index": "not_analyzed"
                    },
                    "@totalTime": {
                      "type": "double"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}'

```

- Index document:

```auto
curl -XPUT "http://localhost:9200/myindex/logs/1" -d'
{
  "@thr": 0,
  "@customData": {
    "Data1": "1"
  },
  "@stk": {
    "@name": "Root",
    "@totalTime": 10,
    "@children": [
      {
        "@name": "SubRoot",
        "@totalTime": 10,
        "@children": [
          {
            "@name": "child1",
            "@totalTime": 5.5
          },
          {
            "@name": "child2",
            "@totalTime": 3.5
          },
          {
            "@name": "child3",
            "@totalTime": 1
          }
        ]
      }
    ]
  }
}'

```

---

<div class="post-metadata">

**Author:** ![Dominique](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dominique/32/9637_2.png) [@Dominique](https://discuss.elastic.co/u/Dominique)\
**Post date:** [May 20, 2016, 7:21am UTC](https://discuss.elastic.co/t/nested-issue/49407/8 "2016-05-20T07:21:06Z")

</div>

Hi,

Thanks a lot. Indeed, with XPUT, I insert well in elasticsearch, so I guess my issue is in logstash. I'll check in this side.  
I'll try to do a graph in kibana with split by @stk.@children.@children, and the result is absolutely false: child1, child2 and child3 have both 3.33 as totalTime instead of 5.5, 3.5 and 1.  
Is there a way to do a visualization with right value per nested children ?

Thanks

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [May 20, 2016, 8:02am UTC](https://discuss.elastic.co/t/nested-issue/49407/9 "2016-05-20T08:02:20Z")

</div>

Kibana doesn't support the nested query/aggregations, but there is an issue tracking this feature request:

> <https://github.com/elastic/kibana/issues/1084>

---

<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 5, 2017, 10:50pm UTC](https://discuss.elastic.co/t/nested-issue/49407/10 "2017-07-05T22:50:11Z")

</div>


