You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Hazelcast 5.2.1中如何为IMap的Key字段创建索引?

Hazelcast 5.2.1 为IMap Key字段创建索引的正确配置方式

问题背景

你使用IMap<Event, Long>结构(Event为POJO类),需要为Key的eventType字段创建索引。在3.12.12版本中通过__key#eventType配置可正常工作,但升级到5.2.1版本后,沿用该语法触发异常:

java.lang.IllegalArgumentException: There is no suitable accessor for ‘__key#eventType’ on class ‘java.lang.Long’

解决方案

Hazelcast 5.x版本对索引配置语法做了调整,旧的__key#前缀已被废弃,需使用key.<字段名>的格式指定Key对象的属性。

基础索引配置

<indexes>
    <index>
         <attributes>
            <attribute>key.eventType</attribute>
         </attributes>
    </index>
</indexes>

有序索引配置

如果需要创建有序索引,添加ordered="true"属性即可:

<indexes>
    <index ordered="true">
         <attributes>
            <attribute>key.eventType</attribute>
         </attributes>
    </index>
</indexes>

说明

新版本使用key.前缀可明确指定索引目标为Map的Key对象属性,而非Value对象,既消除了旧语法的歧义,也符合新版本的配置规范。

内容的提问来源于stack exchange,提问作者张玉洁

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 17:25:18