Skip to content

Instantly share code, notes, and snippets.

@akahn
Created November 5, 2013 02:26
Show Gist options
  • Select an option

  • Save akahn/7312832 to your computer and use it in GitHub Desktop.

Select an option

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

akahn commented Nov 5, 2013

Copy link
Copy Markdown
Author

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

akahn commented Nov 5, 2013

Copy link
Copy Markdown
Author

@karmi

karmi commented Nov 5, 2013

Copy link
Copy Markdown

@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

akahn commented Nov 5, 2013

Copy link
Copy Markdown
Author

@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