Skip to content

Instantly share code, notes, and snippets.

@radu-gheorghe
Created July 10, 2013 08:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radu-gheorghe/5964376 to your computer and use it in GitHub Desktop.
Save radu-gheorghe/5964376 to your computer and use it in GitHub Desktop.
Elasticsearch: If you create a mapping with the ID field pointing to a certain path, inserting two docs with the same ID should overwrite, instead of throwing an error. Unless you specify to "create" documents
#!/bin/bash
curl -XDELETE localhost:9200/test
curl -XPUT localhost:9200/test
curl -XPUT localhost:9200/test/test/_mapping -d '{
"test": {
"_id": {
"path": "foo"
}
}
}'
echo
echo "should be OK"
curl -XPOST localhost:9200/test/test/ -d '{"foo": "bar"}'
echo
echo "should be OK again"
curl -XPOST localhost:9200/test/test/ -d '{"foo": "bar"}'
echo
echo '{ "index": { "_index": "test", "_type": "test"}}
{"foo": "bar"}' > /tmp/bla
echo
echo "bulks should be OK as well"
curl -XPOST localhost:9200/_bulk --data-binary @/tmp/bla
echo
echo
echo "This should fail, though"
curl -XPOST localhost:9200/test/test/?op_type=create -d '{"foo": "bar"}'
echo
echo "And bulk creates too"
echo '{ "create": { "_index": "test", "_type": "test"}}
{"foo": "bar"}' > /tmp/bla
curl -XPOST localhost:9200/_bulk --data-binary @/tmp/bla
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment