Elastic Mapper - Generate ElasticSearch Type Mapping
I'm using Reflection to try and auto-generate ElasticSearch mapping JSON.
I don't currently check or respect the json tags to see if the name rendered
is the same as what would be if the object is serialized so don't use this in
production! It works for a very specific use-case with lots of autogenerated
code I'm dealing with.
I've also hard-coded a check for time.Time and I'm sure there's a better way
of doing this.
Hopefully this snippet outgrows this repository and becomes a tool by itself.
github.com/Jeffail/gabs made it really easy
to generate a complex JSON tree.
Text vs Keyword fields
Use elasticmapper:"text" to specify that a string field is text. Otherwise I
assume it is a keyword. I should make this bit configurable as a flag to decide
what the default is.
Nested Objects
Logically, you want an array of structs to be a nested object. Nested structs
are just simple objects that ElasticSearch can flatten.
ElasticSearch Documentation References