How to add a secondary index with the Java client

Brian Roach roach at
Mon Apr 8 17:48:30 EDT 2013


If you're just passing in an instance of the core Java HashMap ... you can't.

The way the default JSONConverter works for metadata (such as indexes)
is via annotations.

The object being passed in needs to have a field annotated with
@RiakIndex("index_name"). That field can be a Long/Set<Long> or
String/Set<String> (for _int and _bin indexes respectively).

These are not converted to JSON so they won't affect your serialized
data. You can have multiple fields for multiple indexes.

You don't have to append "_int" or "_bin" to the index name in the
annotation - it's done automatically based on the type.

Easiest thing to do woud be to extend HashMap and simply add the
annotated field(s).


On Mon, Apr 8, 2013 at 2:56 PM, Jeff Peck <jeffp at> wrote:
> Hello,
> I have been looking through the documentation for an example of how to add a secondary index in Riak, using the Java client.
> I am currently storing my object (which is a HashMap) like this:
>, docHashMap).execute();
> What would I need to do to add an index to that object before it gets stored?
> Thanks,
> Jeff
> _______________________________________________
> riak-users mailing list
> riak-users at

More information about the riak-users mailing list