Indexes: Indexing Counters

Counter names can be indexed using CounterNamesFor.

Indexing and Counters

Please note that re-indexation will only happen when counter is added or deleted from the document. The counter increments will not trigger the process.

Creating Indexes

The CounterNamesFor method returns all of the counter names for a document passed as the first argument.

List<String> CounterNamesFor(Object doc);

public static class Companies_ByCounterNames extends AbstractIndexCreationTask {
    public Companies_ByCounterNames() {
        map = "from e in docs.Employees\n" +
            "let counterNames = CounterNamesFor(e)\n" +
            "select new\n" +
            "{\n" +
            "   counterNames = counterNames.ToArray()\n" +
            "}";
    }
}

Example

// return all companies that have 'Likes' counter
List<Company> companies = session
    .query(Company.class, Companies_ByCounterNames.class)
    .containsAny("counterNames", Lists.newArrayList("Likes"))
    .toList();