API Methods
Flex exposes the full elasticsearch API as own class methods. You will need to use them directly only for advanced usage, however Flex uses them internally and creates them with just a few lines of yaml. Indeed they are just generated by Generic Templates (see Flex Generic Templates).
The naming of these methods tries to conform with the original elasticsearch documentation, and adds a few aliases for convenience.
As any template-generated method, they accept a list of variables (hashes) for interpolation (see Variables and Interpolation). This documentation reports the underlying templates and the usage examples complete with all the accepted variable, for completeness. Please, notice that you can omit variables that have defaults.
When an API has flags/parameters, you can pass them as the :params variable; when it has structured data you can pass it as the :data variable.
Notice: you can get the updated full reference and usage example of these methods also in the console at any time, by just writing
Flex.doc(for the full API) orFlex.doc :create_index, :get_index_mapping, ...(for specific methods).
This document is updated to elasticsearch version 0.90.2
Core API
| Index | |
|---|---|
Flex.store
|
Stores a document into the index using Template Usage
|
Flex.put_store
|
Alias of |
Flex.post_store
|
Stores a document into the index using Template Usage
|
| Delete | |
Flex.remove
|
Removes a document from the index. Template Usage |
| Get | |
Flex.get
|
Retrieves a document from the index. Template Usage |
Flex.get_source
|
Retrieves the source of a document from the index. Template Usage |
| Multi Get | |
Flex.multi_get
|
Retrieves multiple documents Template Usage |
| Update | |
Flex.update
|
Updates a document based on a script provided. Template Usage You must pass script or doc and the other options as the :data variable |
| Search | |
YourClass.your_custom_search
|
The Search API is completely covered by the Flex Templating system and mostly covered by the |
| Multi Search | |
YourClass.flex.multi_search
|
The method allows you to do multi-searching by using multiple templates defined by your class. It takes 2 arguments. The first is a required hash with the templates names as the keys and the variable hash as the values. You can also use an array of arrays. The second is an optional hash of variables that will be used to render the Template Usage |
| Percolate | |
Flex.put_percolator
|
Registers a named percolator query against an index. Template Usage |
Flex.delete_percolator
|
Unregisters a named percolator. Template Usage |
Flex.percolate
|
Percolates a document. Template Usage
|
| Bulk | |
Flex.post_bulk_string
|
Performs many index/create/update/delete operations in a single API call. Template Usage It may return (see flex:import and Bulk Support) |
| Count | |
Flex.count
|
Gets the number of matches for a query. Template Usage |
| Delete by Query | |
Flex.delete_by_query
|
Allows to delete documents from one or more indices and one or more types based on a query. Template Usage
|
| More Like This | |
Flex.more_like_this
|
Allows to get documents that are “like” a specified document. Template Usage
|
Flex.mlt
|
Alias for |
| Validate | |
Flex.validate
|
Allows to validate a potentially expensive query without executing it. Template Usage
|
| Explain | |
Flex.explain
|
Computes a score explanation for a query and a specific document. Template Usage
|
| Flex Additions | |
Flex.match_all
|
Not a real API method, but handy: Template Usage |
Flex.search_by_id
|
Get a document without using the get API (which doesn’t support fields ’*’) Template Usage
|
Flex.scan_search
|
Generic implementation of the elasticsearch search_type API of type Usage |
Flex.scan_all
|
Specific implementation of the elasticsearch search_type API of type Usage |
Flex.dump_all
|
It Usage |
Flex.dump_one
|
It Usage |
Indices API
| Aliases | |
|---|---|
Flex.post_index_aliases
|
The index aliases API allow to alias an index with a name, with all APIs automatically converting the alias name to the actual index name. Template Usage
|
Flex.get_index_aliases
|
Returns all indices with all aliases, or just for specific indices. (pre 0.90.1). Template Usage |
Flex.add_index_alias
|
Adds an index alias. Template Usage
|
Flex.delete_index_alias
|
Deletes an index alias. Template Usage |
Flex.get_index_alias
|
Allows to filter by alias name and index name. Template Usage |
| Analyze | |
Flex.analyze_index
|
Performs the analysis process on a text and return the tokens breakdown of the text. Template Usage
|
| Create Index | |
Flex.create_index
|
Allows to instantiate an index. (Uses Template Usage |
Flex.put_index
|
Alias for |
Flex.post_index
|
Allows to instantiate an index. (Uses Template Usage |
| Delete Index | |
Flex.delete_index
|
Allows to delete an existing index. Template Usage |
| Open/Close Index | |
Flex.close_index
|
Allows to close an index. Template Usage |
Flex.open_index
|
Allows to open an index. Template Usage |
| Get Settings | |
Flex.get_index_settings
|
Allows to retrieve settings of index/indices. Template Usage |
Flex.get_settings
|
Alias for |
| Get Mapping | |
Flex.get_index_mapping
|
Allows to retrieve the mapping of index/indices. Template Usage |
Flex.get_mapping
|
Alias for |
| Put Mapping | |
Flex.put_index_mapping
|
Allows to register specific mapping definition for a specific type. Template Usage |
Flex.put_mapping
|
Alias for |
| Delete Mapping | |
Flex.delete_index_mapping
|
Allows to delete the mapping of an index/type. Template Usage |
Flex.delete_mapping
|
Alias for |
| Refresh | |
Flex.refresh_index
|
Allows to explicitly refresh one or more index. Template Usage |
| Optimize | |
Flex.optimize_index
|
Allows to optimize one or more index. Template Usage
|
| Flush | |
Flex.flush_index
|
Allows to flush one or more index. Template Usage
|
| Snapshot | |
Flex.gateway_snapshot
|
Allows to explicitly perform a snapshot through the gateway of one or more indices (backup them). Template Usage |
| Update | |
Flex.update_index_settings
|
Change specific index level settings in real time. Template Usage
|
| Templates | |
Flex.put_index_template
|
Creates a template that will automatically be applied to new indices created. Template Usage
|
Flex.delete_index_template
|
Deletes an existing template. Template Usage |
Flex.get_index_template
|
Retrieves an existing template. Template Usage |
| Warmers | |
Flex.put_index_warmer
|
Creates a warmer to warm up the index before it is available for search. Template Usage
|
Flex.delete_index_warmer
|
Deletes an existing warmer. Template Usage |
Flex.get_index_warmer
|
Retrieves an existing warmer. Template Usage |
| Stats | |
Flex.index_stats
|
Provides statistics on different operations happening on an index. Template Usage |
Flex.stats
|
Alias for |
| Status | |
Flex.index_status
|
Provides a comprehensive status information of one or more indices. Template Usage |
| Segments | |
Flex.index_segments
|
Provides low level segments information that a Lucene index (shard level) is built with. Template Usage |
| Clear Cache | |
Flex.index_clearcache
|
Clears either all caches or specific cached associated with one ore more indices. Template Usage |
| Indices Exists | |
Flex.indices_exists
|
Checks if the index/indices exists. Template Usage
|
Flex.exist?
|
Alias for |
| Types Exists | |
Flex.types_exists
|
Checks if the type/types exists in an index/indices. Template Usage
|
Flex.exist?
|
Alias for |
Cluster API
| Health | |
|---|---|
Flex.cluster_health
|
Gets a very simple status on the health of the cluster. Template Usage
|
| State | |
Flex.cluster_state
|
Gets a comprehensive state information of the whole cluster. Template Usage
|
| Update Settings | |
Flex.put_cluster_settings
|
Updates cluster wide specific settings. Template Usage
|
Flex.get_cluster_settings
|
Retrieves cluster settings. Template Usage |
| Nodes Info | |
Flex.cluster_nodes_info
|
Retrieves one or more (or all) of the cluster nodes information. Template Usage |
| Nodes Stats | |
Flex.cluster_nodes_info
|
Retrieves one or more (or all) of the cluster nodes statistics. Template Usage |
| Nodes Shutdown | |
Flex.cluster_nodes_shutdown
|
Shutdown one or more (or all) nodes in the cluster. Template Usage |
| Nodes Hot Threads | |
Flex.cluster_nodes_hot_threads
|
Gets the current hot threads on each node in the cluster. Template Usage |
| Cluster Reroute | |
Flex.cluster_reroute
|
Explicitly execute a cluster reroute allocation command including specific commands. Template Usage You can pass the data structure as the |
If you find any elasticsearch API missing from this list, please, let me know and I will add it right away (it should be just a matter of a few minutes)