Skip to content

Instantly share code, notes, and snippets.

@akahn
Created November 5, 2013 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akahn/7312832 to your computer and use it in GitHub Desktop.
Save akahn/7312832 to your computer and use it in GitHub Desktop.
Trying to understand elasticsearch's schema and types
$ curl -XPOST http://localhost:9200/myindex/mytype -d '{"foo": ["bar"]}'
{"ok":true,"_index":"myindex","_type":"mytype","_id":"YYfPUL3TQLaL17zhXQ-ELw","_version":1}
$ curl -XPOST http://localhost:9200/myindex/mytype -d '{"foo": [{"foo": "bar"}]}'
{"error":"MapperParsingException[Failed to parse [foo]]; nested: ElasticSearchIllegalArgumentException[unknown property [foo]]; ","status":400}
$ curl -XDELETE http://localhost:9200/myindex/mytype
{"ok":true}
$ curl -XPOST http://localhost:9200/myindex/mytype -d '{"foo": [{"foo": "bar"}]}'
{"ok":true,"_index":"myindex","_type":"mytype","_id":"6Sv7aaBXTu2jH_wYXR4SYg","_version":1}
$ curl -XPOST http://localhost:9200/myindex/mytype -d '{"foo": ["bar"]}'
{"error":"MapperParsingException[object mapping [foo] trying to serialize a value with no field associated with it, current value [bar]]","status":400}
# Why are a list ["foo"] and a list of objects [{"foo": "bar"}] incompatible?
# How should I rearrange my data for storage in an elasticsearch document?
@akahn
Copy link
Author

akahn commented Nov 5, 2013

By the way, the data I'm collecting consists of Ruby method arguments. Elements in the list can be strings, numbers, hashes or lists.

@akahn
Copy link
Author

akahn commented Nov 5, 2013

@karmi
Copy link

karmi commented Nov 5, 2013

@akahn, well, it could be argued that ["foo"] and [{"foo" : "bar"}] are quite a different thing. Why do you think these two should be compatible?

@akahn
Copy link
Author

akahn commented Nov 5, 2013

@karmi You're right. I think I thought they should be compatible because I misunderstood elasticsearch's definition of 'schemaless'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment