# Validation failed because of missing type with bulk API

**URL:** <https://discuss.elastic.co/t/validation-failed-because-of-missing-type-with-bulk-api/118465>\
**Category:** Elasticsearch\
**Created:** [February 5, 2018, 1:54pm UTC](https://discuss.elastic.co/t/validation-failed-because-of-missing-type-with-bulk-api/118465 "2018-02-05T13:54:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomak](https://avatars.discourse-cdn.com/v4/letter/t/d9b06d/32.png) [@tomak](https://discuss.elastic.co/u/tomak)\
**Post date:** [February 5, 2018, 1:54pm UTC](https://discuss.elastic.co/t/validation-failed-because-of-missing-type-with-bulk-api/118465/1 "2018-02-05T13:54:16Z")

</div>

Hello,

I would like to add the following JSON file using the bulk API

```
"index":{"_id":"1"}
"info":"1"

```

however I get the following error

```
"type" : "action_request_validation_exception",
"reason" : "Validation Failed: 1: type is missing;"

```

I did the following in the Kibana console So I don't see why I'm getting a mistake:

```
PUT /fake
{
 "mappings": {
  "doc": {
   "properties": {
    "info": {"type": "keyword"}
   }
  }
 }
}
```

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [February 5, 2018, 1:57pm UTC](https://discuss.elastic.co/t/validation-failed-because-of-missing-type-with-bulk-api/118465/2 "2018-02-05T13:57:20Z")

</div>

It looks like your payload is not properly formed. It must look like this:

```
POST /your_index/your_type/_bulk
{"index":{"_id":"1"}}
{"info":"1"}

```

or

```
POST /_bulk
{"index":{"_index": "your_index", "_type": "your_type", "_id":"1"}}
{"info":"1"}
```

---

<div class="post-metadata">

**Author:** ![tomak](https://avatars.discourse-cdn.com/v4/letter/t/d9b06d/32.png) [@tomak](https://discuss.elastic.co/u/tomak)\
**Post date:** [February 5, 2018, 2:06pm UTC](https://discuss.elastic.co/t/validation-failed-because-of-missing-type-with-bulk-api/118465/3 "2018-02-05T14:06:40Z")

</div>

OK. But how Do I make this work from the terminal? Because in practice, I will want to add a much bigger JSON file.

If I understand correctly, in your' solution, you are not passing through a separate file.

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [February 5, 2018, 2:09pm UTC](https://discuss.elastic.co/t/validation-failed-because-of-missing-type-with-bulk-api/118465/4 "2018-02-05T14:09:31Z")

</div>

You can do exactly the same from the terminal.

Create a bulk file with this content (also make sure that there is a newline on the last line):

```
{"index":{"_index": "your_index", "_type": "your_type", "_id":"1"}}
{"info":"1"}
{"index":{"_index": "your_index", "_type": "your_type", "_id":"2"}}
{"info":"2"}
{"index":{"_index": "your_index", "_type": "your_type", "_id":"3"}}
{"info":"3"}

```

Then you can use `curl` to send that file to the `_bulk` endpoint like this:

```
curl -XPOST -H 'Content-Type: application/json' localhost:9200/_bulk --data-binary @/path/to/your_file.json
```

---

<div class="post-metadata">

**Author:** ![tomak](https://avatars.discourse-cdn.com/v4/letter/t/d9b06d/32.png) [@tomak](https://discuss.elastic.co/u/tomak)\
**Post date:** [February 5, 2018, 2:23pm UTC](https://discuss.elastic.co/t/validation-failed-because-of-missing-type-with-bulk-api/118465/5 "2018-02-05T14:23:29Z")

</div>

Thanks this works very well.

(Maybe it's better if I open a new subject)

Is the type then defined as the same for each element in the line (in case I have multiple elements)?

I was wondering also what the different types were?

I know integer and keyword. Is there a type for "indentation"?

Like if I would have my JSON file like this:

```
{"_id":{"$oid":"52287a4ee4b07193f703c23f"}}

```

Plus is there a way of defining the type and index once and for all for a JSON file (because it will be the same thing for each line)

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [February 5, 2018, 2:30pm UTC](https://discuss.elastic.co/t/validation-failed-because-of-missing-type-with-bulk-api/118465/6 "2018-02-05T14:30:04Z")

</div>

I guess it's better to ask another question, so we can keep a single subject per question.  
Feel free to reference your new question from this one, though.

---

<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, 2018, 2:30pm UTC](https://discuss.elastic.co/t/validation-failed-because-of-missing-type-with-bulk-api/118465/7 "2018-03-05T14:30:11Z")

</div>

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