Created
September 23, 2011 04:02
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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