javahazelcasthazelcast-imap

How to create index map in Hazelcast running as separate server


we are using Predicate API for querying the map in Hazelcast (4.2). I've found a doc how to add index to the map (https://docs.hazelcast.com/imdg/4.2/query/how-distributed-query-works#indexing-queries). Unfortunately, all configuration I've found is related to case of embedded cluster with application instance being a member. But we are using client-server topology with Hazelcast running at separate server and applications connecting to it as clients. ClientConfig doesn't have a possibility to add index (except to near cache).

I wonder, how can we add indexes to maps on the Hazelcast server? Or did I misunderstand the way how the predicate will be processed and it is enough to set indexes on near caches?


Solution

  • There are 2 ways how you can add indexes from the client.

    If your map doesn't exist yet you can dynamically add map config with an index config:

    HazelcastInstance client = ...
    
    MapConfig mapConfig = new MapConfig("my-map")
        .addIndexConfig(new IndexConfig(IndexType.HASH, "name"));
    
    client.getConfig().addMapConfig(mapConfig);
    

    If your map already exists you can use addIndex on the map itself:

    HazelcastInstance client = ...
    
    IMap<Object, Object> clientMap = client.getMap("my-map");
    clientMap.addIndex(new IndexConfig(IndexType.HASH, "name"));