openannotation/annotator-store — pull request #111 by Treora (2014-12-28 00:33:57+00:00)
Title: [WIP] Support custom analysers

To support custom analysers, it seems best to abandon model.create_all
in favour of an index-wide method (es.create_models) that sets all
mappings (and custom analysis settings) at once.

Code is largely transplanted from hypothesis/h#1825

Details:
Custom analysers(&filters&tokenisers) are shared in Elasticsearch among
all document types (models). To update a model's mappings one needs to
make sure the custom analysers are defined first, but updating those
just for one model is inelegant; The index would have to be closed for
each update, and one cannot check for duplicate definitions of analysers
as it is not visible which model defined a particular analyser. Treating
index-wide settings as per-model settings creates leaky abstractions.

@tilgovi, @nickstenning (and anyone concerned): Please let me know if you disagree with abandoning the model-centric abstraction in this case. I think it is better this way because Elasticsearch does not group analysers by document type, so if we do pretend that it does we either get leaky abstractions with possibly unreliable edge cases, or we need to do more effort than it's worth to pertain the model-centric abstraction.
We could even consider to just define analysers centrally instead of in each model, to simplify things even further (no merging of settings required, it would just match ES's structure), but I think I'm okay with this approach.

I will do tests, add tests and polish things when the approach is considered satisfactory.