Skip to content

Instantly share code, notes, and snippets.

@jeremy
Created September 23, 2011 04:02
Show Gist options
  • Save jeremy/1236728 to your computer and use it in GitHub Desktop.
Save jeremy/1236728 to your computer and use it in GitHub Desktop.
elasticsearch required _routing must have an explicit field mapping for non-string fields
#!/usr/bin/env bash
# https://github.com/elasticsearch/elasticsearch/issues/1357
set -o verbose
curl -s -XGET http://localhost:9200/ |grep -B 1 number
curl -XDELETE http://localhost:9200/foo
curl -XPUT http://localhost:9200/foo -d '{
"mappings": {
"bar": {
"_routing": { "required": true, "path":"baz" },
"properties": { "baz": { "type":"string", "store":true }}
}}}'
curl -X POST http://localhost:9200/foo/bar -d '{"baz":1}'
# ^ Works when field 'baz' is explicitly mapped and stored.
curl -XDELETE http://localhost:9200/foo
curl -XPUT http://localhost:9200/foo -d '{
"mappings": {
"bar": {
"_routing": { "required": true, "path":"baz" },
"properties": { "baz": { "type":"string", "store":false }}
}}}'
curl -X POST http://localhost:9200/foo/bar -d '{"baz":1}'
# ^ Works even when 'baz' isn't stored as long as it's explicitly mapped.
curl -XDELETE http://localhost:9200/foo
curl -XPUT http://localhost:9200/foo -d '{
"mappings": {
"bar": {
"_routing": { "required": true, "path":"baz" }
}}}'
curl -X POST http://localhost:9200/foo/bar -d '{"baz":"abc"}'
# ^ Works when 'baz' is unmapped, but first value is a string.
curl -XDELETE http://localhost:9200/foo
curl -XPUT http://localhost:9200/foo -d '{
"mappings": {
"bar": {
"_routing": { "required": true, "path":"baz" },
"properties": { "baz": { "type":"integer" }}
}}}'
curl -X POST http://localhost:9200/foo/bar -d '{"baz":1}'
# ^ Fails when 'baz' is explicitly mapped as an integer.
# ^ Should this work?
curl -XDELETE http://localhost:9200/foo
curl -XPUT http://localhost:9200/foo -d '{
"mappings": {
"bar": {
"_routing": { "required": true, "path":"baz" }
}}}'
curl -X POST http://localhost:9200/foo/bar -d '{"baz":1}'
# ^ Fails when 'baz' is unmapped and first doc has an integer value.
# ^ Should this work?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment