Flex::ModelIndexer

Notice: The Flex::ModelIndexer includes also Flex::ModelSyncer (see Flex::ModelSyncer)

Flex avoids polluting your models with many methods: indeed it adds just 1 class method and 3 instance methods, all starting with the flex prefix to avoid confusion:

Besides you can define a Model.flex_result method in order to customize the results (see Model.flex_result)

Class Methods

flex

You access all the Flex features included in your model through the flex proxy object. It implements the methods to map your models to the elasticsearch index, define parent/child relationships and sync.

flex.index

By default the index used for all the models in your app is the Flex::Configuration.variables[:index]. In a rails app that gets set before initializing the app (see Configuration). You can map your model to another index by explicitly setting it in your class.

flex.index = 'foo'
flex.type

By default the type used for your model is the full-underscored class name. For example MyModel::SuperSpecial will generate my_model__super_special. Notice the double underscore in place of the commonly used slash, which avoids url conflicts. You can map your model to another type by explicitly setting it in your class:

      flex.type = 'bar'
      
flex.parent

Defines elasticsearch parent/child relations (see Indexing Records).

flex.sync(*synced)

Implemented by the Flex::ModelSyncer module (see flex.sync).

flex.synced

Implemented by the Flex::ModelSyncer module (see flex.synced).

flex_result(result)

Custom defined method (see Model.flex_result).

Instance Methods

You usually don’t need to deal with this methods unless you sync manually or have very special needs.

flex

The flex instance object is mostly used internally, however you can access all the Flex features included in your records through it. It implements the methods to manage the elasticsearch document related to your record.

flex.index

The index for this record.

flex.type

The document type for this record.

flex.store

Indexes the flex_source of this record. It is used internally and you don’t need to use this directly if you use Model.flex.sync on this model.

flex.remove

Removes the elasticsearch document for this record. It is used internally and you don’t need to use this directly if you use Model.flex.sync on this model.

flex.sync

Implemented by the Flex::ModelSyncer module (see flex.sync).

flex.get

Retrieves the elasticsearch document from the index. The result is extended as usual (see Flex Extenders, Flex Model Extenders and Flex Rails Extenders). Mostly useful in the console to inspect the elasticsearch related document.

>> comment = Comment.first
>> comment.flex.get
=> {"_index"=>"my_index", "_type"=>"review_comment","_id"=>"4f15d2712c16bf4337000012", ... }
flex_source

(see Indexing Records)

flex_indexable?

(see Indexing Fields)

Overriding Flex Metafields
flex_id, flex_index, flex_type, flex_parent, flex_routing

Use only if you know what you are doing!

You define any of this methods in your model, if you want to override the flex.id, flex.index, flex.type, flex.parent and/or flex.routing generation.

The flex_index should be used if you want to implement dynamic indices in your model.