Types for JSON file using bulk API


I would like to add a JSON file with a lot of lines like this.

{"index":{"_index": "fake", "_type": "keyword", "_id":"2"}}
{"info":"2", "bob":3}

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)

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:


(Val Crettaz) #2

Like I mentioned in my previous answer, you can remove the index and type information from your JSON file like this:

{"info":"2", "bob":3}

and then add those to your curl command

curl -XPOST -H 'Content-Type: application/json' localhost:9200/fake/type/_bulk --data-binary @/path/to/your/file.json

Also note that the type information has nothing to do with your field types (keyword, integer, etc), but it is a mapping type, i.e. the place where you define all your index fields

Finally, the _id can only take literal value, but not an object value. You could hash {"$oid":"52287a4ee4b07193f703c23f"} into some string and use that string as ID, though


Sorry I didn't pay attention and didn't see the "type" in your curl.

(system) #4

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