tomak
February 5, 2018, 1:54pm
1
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"}
}
}
}
}
val
(Val Crettaz)
February 5, 2018, 1:57pm
2
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"}
1 Like
tomak
February 5, 2018, 2:06pm
3
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.
val
(Val Crettaz)
February 5, 2018, 2:09pm
4
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
tomak
February 5, 2018, 2:23pm
5
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)
val
(Val Crettaz)
February 5, 2018, 2:30pm
6
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.
system
(system)
Closed
March 5, 2018, 2:30pm
7
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.