0

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?

Vy Do
  • 46,709
  • 59
  • 215
  • 313
Ivo Š.
  • 23
  • 4

1 Answers1

0

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"));
František Hartman
  • 14,436
  • 2
  • 40
  • 60
  • So it means I have to do after creating the HazelcastInstance.. I didn't thought about that way around, thanks. But what if another client joins the server? Will the attempt to add existing index fail or will it replace the existing index with new empty one? IMap doesn't have a method to check existence of index.. – Ivo Š. Jan 26 '22 at 15:56