Self Documentation

Elastics is aware of your templates, partials, the tags they use, whether they are required or have defaults, and can suggest you the usage of the methods it creates for you.

You can get the complete info, with the (erb expanded) templates and partials used by each generated method, plus a commented example of its usage, by just calling doc on the elastics proxy object of your class. For example:

doc

>> MyClass.elastics.doc :full_search

#  ########## MyClass.full_search ##########
#
#  --------------------------
#  Elastics::Template::Search
#  ---
#  full_search:
#    - query:
#        bool:
#          must:
#            - query_string:
#                query: <<q= '*' >>
#            - << _filter_terms= ~ >>
#      aggregations:
#        keywords:
#          terms:
#            field: keywords
#        foo:
#          terms:
#            field: foo
#        bar:
#          terms:
#            field: bar
#
#  ---------------------------
#  Elastics::Template::Partial
#  ---
#  _filter_terms:
#    term: <<facet_hash>>
#
#
#  Usage:
#  MyClass.full_search :_filter_terms => nil,         # partial
#                      :type          => type,        # required
#                      :index         => "test",
#                      :q             => "*"
#
def MyClass.full_search(*vars)
  # this is a stub, used for reference
end

The info for a method contains the template and partial(s) eventually used, plus an usage example.

IMPORTANT: the usage example is not generic. It actually shows you a working sample of code, with the variables set with their evaluated default coming from your code or with a stub variable name. Keep an eye on the values of the variables in order to know more about them.

That output is suitable for being copied and pasted right in your class, just before the elastics.load_* call that will overrides the stubs. Notice that stubs are very useful in order to make some IDE work properly with autogenerated methods (e.g. RubyMine).

You can get the self documetation of all the methods your class defines, by just not passing any template name to the doc method.

Notice: you can get the self documentation also for the Elastics API Methods by doing the same with the Elastics module (see API Methods):

>> Elastics.doc

There are a few other methods that can help when you are looking for documentation:

usage

usage prints just the usage of the method:

>> MyClass.elastics.usage :full_search

MyClass.full_search :_filter_terms => nil,         # partial
                    :type          => type,        # required
                    :index         => "test",
                    :q             => "*"

### find(pattern_or_String)

find prints a list of methods that contains the pattern_or_string:

>> Elastics.find 'get'
---
- :get
- :get_source
- :multi_get_ids
- :multi_get_docs
- :get_index
- :get_index_mapping
- :get_field_mapping
- :get_index_aliases
- :get_index_alias
- :get_index_settings
- :get_index_template
- :get_index_warmer
- :get_cluster_settings