# Unable to push documents and index patterns in indexes in kibana plugin using core api

**URL:** <https://discuss.elastic.co/t/unable-to-push-documents-and-index-patterns-in-indexes-in-kibana-plugin-using-core-api/277508>\
**Category:** Kibana\
**Tags:** kibana-plugin-development\
**Created:** [July 1, 2021, 5:22am UTC](https://discuss.elastic.co/t/unable-to-push-documents-and-index-patterns-in-indexes-in-kibana-plugin-using-core-api/277508 "2021-07-01T05:22:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kibanaPluginDev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kibanaplugindev/32/87937_2.png) [@kibanaPluginDev](https://discuss.elastic.co/u/kibanaPluginDev)\
**Post date:** [July 1, 2021, 5:22am UTC](https://discuss.elastic.co/t/unable-to-push-documents-and-index-patterns-in-indexes-in-kibana-plugin-using-core-api/277508/1 "2021-07-01T05:22:27Z")

</div>

I am unable to push the documents in the newly created index and add new fields to it using the kibana core API . Although I was able to do it with the dev tool. i want to implement this feature in my plugin to add documents and add new fields to it.  
Something like this -  
POST index name/type  
{  
"document1":"value"  
}

 ![Screenshot 2021-06-24 at 3.53.59 PM](https://us1.discourse-cdn.com/elastic/original/3X/6/5/659a0d0f69af6db01788c807a0cd58ad7a4c6a21.png)

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [July 1, 2021, 8:54am UTC](https://discuss.elastic.co/t/unable-to-push-documents-and-index-patterns-in-indexes-in-kibana-plugin-using-core-api/277508/2 "2021-07-01T08:54:12Z")

</div>

Can you share the code you used?

---

<div class="post-metadata">

**Author:** ![kibanaPluginDev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kibanaplugindev/32/87937_2.png) [@kibanaPluginDev](https://discuss.elastic.co/u/kibanaPluginDev)\
**Post date:** [July 1, 2021, 9:00am UTC](https://discuss.elastic.co/t/unable-to-push-documents-and-index-patterns-in-indexes-in-kibana-plugin-using-core-api/277508/3 "2021-07-01T09:00:14Z")

</div>

Hello @flash1293 ,

> [router.post](https://router.post)(  
> {  
> path: '/api/sip/addIndex',  
> validate: false,  
> },  
> async (context, request, response) =\> {  
> const body = {  
> mappings: {  
> properties: {  
> field1: { type: 'text' },  
> },  
> },  
> };  
> const results = await context.core.elasticsearch.client.asCurrentUser.indices.create({  
> index: 'harshit3',  
> body,  
> });  
> return response.ok({  
> body: { results },  
> });  
> }  
> );  
> I was able to create indexes using this piece of code . Now I want to add documents in the way I provided in the screenshot along with some new fields . Any suggestions how can I implement this?

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [July 1, 2021, 3:38pm UTC](https://discuss.elastic.co/t/unable-to-push-documents-and-index-patterns-in-indexes-in-kibana-plugin-using-core-api/277508/4 "2021-07-01T15:38:52Z")

</div>

the `context.core.elasticsearch.client.asCurrentUser.create` method should allow you to create write new documents.

---

<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 29, 2021, 3:39pm UTC](https://discuss.elastic.co/t/unable-to-push-documents-and-index-patterns-in-indexes-in-kibana-plugin-using-core-api/277508/5 "2021-07-29T15:39:10Z")

</div>

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