# Create document which nested fields does not work correctly in elasticsearch.js

**URL:** <https://discuss.elastic.co/t/create-document-which-nested-fields-does-not-work-correctly-in-elasticsearch-js/73992>\
**Category:** Elasticsearch\
**Created:** [February 5, 2017, 7:24pm UTC](https://discuss.elastic.co/t/create-document-which-nested-fields-does-not-work-correctly-in-elasticsearch-js/73992 "2017-02-05T19:24:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![katihaumann](https://avatars.discourse-cdn.com/v4/letter/k/f05b48/32.png) [@katihaumann](https://discuss.elastic.co/u/katihaumann)\
**Post date:** [February 5, 2017, 7:24pm UTC](https://discuss.elastic.co/t/create-document-which-nested-fields-does-not-work-correctly-in-elasticsearch-js/73992/1 "2017-02-05T19:24:41Z")

</div>

elasticsearch.js. Version: 12.1.3

If I try to create a document which contains nested fields then only the fields of the enclosing document are saved but the nested document not. Here is an example code:

```
const elasticsearch = require('elasticsearch');
client = new elasticsearch.Client();
client.indices.create({
   index: 'myindex',
   body: {
      mappings: {
         book: {
            properties: {
               title: {
                  type: 'text'
               },
               authors: {
                  'type': 'nested',
                  'properties': {
                     'name': {
                        'type': 'test'
                     }
                  }
               }
            }
         }
      }
   }
})
.then(function() {
   elasticsearchClient.create( {
      index: 'myindex',
      type: 'book',
      id: 1,
      body: {id:1, title: 'my first book', authors: [{name: 'author1'}, {name: 'author2'}]}
   });
});
```

The result in elasticsearch is a book document which contains only the title but not the authors.

Can anybody help me?

---

<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:** [March 5, 2017, 7:25pm UTC](https://discuss.elastic.co/t/create-document-which-nested-fields-does-not-work-correctly-in-elasticsearch-js/73992/2 "2017-03-05T19:25:05Z")

</div>

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