You are currently browsing legacy 4.1 version of documentation. Click here to switch to the newest 5.1 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

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" +


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