Reverbrain wiki

Site Tools


Table of Contents

Secondary indexes

Secondary indexes support were added to Elliptics since version


Secondary indexes is an ability to add Elliptics' documents to secondary indexes for future searching them. Technically list of objects' identificators for certain secondary index is stored as one more data blob by special-key in Elliptics, that makes possible to store secondary indexes with the same reliability as any other user data. Also it's possible to store small amounts of data for all object-index pairs, it's extremly usefull for most of applicable tasks. Since secondary indexes were added to object it should be possible to find objects by them. Right now Elliptics provides two ways to find items by the secondary indexes: by AND (find all objects with all of provided indexes) and OR (find all objects with at least one of provided indexes) logic.


Using of indexes is right easy. Examples are provided by synchronious implementaions for better readibility.

session sess = ...;

std::vector<std::string> indexes = {

sess.update_indexes(id, indexes).wait();

// OR is data is needed

std::vector<index_entry> indexes = {
    { key("fast").raw_id(), data_pointer(...) },

sess.update_indexes(id, indexes).wait();

Searching for objects:

std::vector<std::string> indexes = { ... };
sync_find_indexes_result result = sess.find_all_indexes(indexes);
// sync_find_indexes_result result = sess.find_any_indexes(indexes);

for (auto it = result.begin(); it != result.end(); ++it) {
    find_indexes_result_entry entry = *it;; // Identificator of object by which it's possible to request data from Elliptics
    for (auto jt = entry.indexes.begin(); jt != entry.indexes.end(); ++jt) {
        auto index = *jt;
        index.first; // Index identificator, usually it's sha512 of index name
        index.second; // Data pointer which stores index-specific data for this index
elliptics/secondary-indexes.txt ยท Last modified: 2013/12/09 17:54 by masha