# How to create docs in index using API?

**URL:** <https://discuss.elastic.co/t/how-to-create-docs-in-index-using-api/252566>\
**Category:** Elasticsearch\
**Created:** [October 19, 2020, 2:45pm UTC](https://discuss.elastic.co/t/how-to-create-docs-in-index-using-api/252566 "2020-10-19T14:45:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gosforth](https://avatars.discourse-cdn.com/v4/letter/g/f08c70/32.png) [@Gosforth](https://discuss.elastic.co/u/Gosforth)\
**Post date:** [October 19, 2020, 2:45pm UTC](https://discuss.elastic.co/t/how-to-create-docs-in-index-using-api/252566/1 "2020-10-19T14:45:57Z")

</div>

What I understand \_type is not required now.

So first scenario:

POST host/\_bulk

```auto
{ "index":{ "_index": "myindex"} }
{ "name":"john doe","age":25 }

```

Does not work

Scenario 2:  
POST host/myindex/\_bulk

```auto
{ "index":{ } }
{ "name":"john doe","age":25 }

```

Does not work

Scenario 3:  
POST host/myindex/\_type/\_bulk

```auto
{ "index":{ } }
{ "name":"john doe","age":25 }

```

Does not work

What is the correct query?

---

<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:** [October 19, 2020, 3:16pm UTC](https://discuss.elastic.co/t/how-to-create-docs-in-index-using-api/252566/2 "2020-10-19T15:16:06Z")

</div>

I'd use for now:

```auto
POST /myindex/_doc/_bulk
{ "index": { } }
{ "name": "john doe", "age": 25 }

```

---

<div class="post-metadata">

**Author:** ![Gosforth](https://avatars.discourse-cdn.com/v4/letter/g/f08c70/32.png) [@Gosforth](https://discuss.elastic.co/u/Gosforth)\
**Post date:** [October 21, 2020, 12:42pm UTC](https://discuss.elastic.co/t/how-to-create-docs-in-index-using-api/252566/3 "2020-10-21T12:42:39Z")

</div>

> [@dadoonet](#):
>
> `oc/_bulk`

Thank you. Looks like '\_doc' causes error.

> #! Deprecation: [types removal] Specifying types in bulk requests is deprecated.  
> {  
> "took" : 113,  
> "errors" : false,  
> "items" : [  
> {  
> "index" : {  
> "\_index" : "test\_index",  
> "\_type" : "\_doc",  
> "\_id" : "aJEqS3UBcGLv9iq-EsyO",  
> "\_version" : 1,  
> "result" : "created",  
> "\_shards" : {  
> "total" : 2,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "\_seq\_no" : 0,  
> "\_primary\_term" : 1,  
> "status" : 201  
> }  
> }  
> ]  
> }

Without it, it's fine.

---

<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:** [October 22, 2020, 12:44pm UTC](https://discuss.elastic.co/t/how-to-create-docs-in-index-using-api/252566/4 "2020-10-22T12:44:47Z")

</div>

Right. The right way is to send:

```auto
DELETE /myindex
POST /myindex/_bulk
{ "index": { } }
{ "name": "john doe", "age": 25 }

```

---

<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:** [November 19, 2020, 12:44pm UTC](https://discuss.elastic.co/t/how-to-create-docs-in-index-using-api/252566/5 "2020-11-19T12:44:47Z")

</div>

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