Skip to content

Instantly share code, notes, and snippets.

@radu-gheorghe
Created November 15, 2012 12:11
Show Gist options
  • Save radu-gheorghe/4078353 to your computer and use it in GitHub Desktop.
Save radu-gheorghe/4078353 to your computer and use it in GitHub Desktop.
Elasticsearch bulk insert with index name in URL
$ cat req
{ "index" : { "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
{ "index" : { "_type" : "type1", "_id" : "2" } }
{ "field1" : "value2" }
$ curl -XPOST localhost:9200/testing/_bulk?pretty=true --data-binary @req
{
"took" : 5,
"items" : [ {
"index" : {
"_index" : "testing",
"_type" : "type1",
"_id" : "1",
"_version" : 2,
"ok" : true
}
}, {
"index" : {
"_index" : "testing",
"_type" : "type1",
"_id" : "2",
"_version" : 2,
"ok" : true
}
} ]
}
#note how the index in the file overrides the one in the URL
$ cat req
{ "index" : { "_index": "override", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
{ "index" : { "_index": "override", "_type" : "type1", "_id" : "2" } }
{ "field1" : "value2" }
$ curl -XPOST localhost:9200/testing/_bulk?pretty=true --data-binary @req
{
"took" : 234,
"items" : [ {
"index" : {
"_index" : "override",
"_type" : "type1",
"_id" : "1",
"_version" : 1,
"ok" : true
}
}, {
"index" : {
"_index" : "override",
"_type" : "type1",
"_id" : "2",
"_version" : 1,
"ok" : true
}
} ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment