Hmm, from your explanation on SO I didn't get the "last resort" feeling about
to_indexed_json ("they serve two different purposes"). With the "computed field" comment, I meant that you've chosen examples like this:
ruby # In Tire::Model::Indexing#mapping RDoc indexes :words, :as => 'content.split(/\W/).length' # In README indexes :content_size, :as => 'content.size'
... creating synthesized fields in the elasticsearch index that don't map to actual fields in the source database. That's the "aha" I described about choice of examples after reading the explanation: these seemed consistent with the usage you were suggesting on SO.
Alternatively in my example above, I suppose I could achieve the same thing by eliminating
to_indexed_json and making more elaborate use of
:as options (or nested
indexes blocks?). That seems more troublesome than taking advantage of
to_json with includes, in the case of ActiveRecord. If that is preferable though, perhaps
to_indexed_json should be heavily deemphasized in docs?
As an aside, particularly if
to_indexed_json is considered a last resort, I'm definitely even more fond of the recent pull request that added support for giving a
:as and having that dispatched to a method.