为什么hazelcast无法使用imap和hazelcastjsonvalue查询不正确的结果 [英] why hazelcast can not query incorrect result with imap and hazelcastjsonvalue

查看:68
本文介绍了为什么hazelcast无法使用imap和hazelcastjsonvalue查询不正确的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在hazelcast中使用IMap存储数据,键是字符串,值是hazelcastjsonvalue.代码示例:`

I use IMap store data in hazelcast, key is a string, value is a hazelcastjsonvalue. code example: `

    Gson gson = new Gson();
    String json = "{\"orderId\":\"-20200822-221116-188-quote-100002\",\"securityId\":\"130015\",\"tradingAccount\":\"xtrinterbanktra01\",\"subSystemId\":\"QDM-ESP\",\"userId\":\"xtrinterbankat01\",\"securityExchange\":\"B\",\"systemNodeId\":710,\"quoteId\":\"1598145974197\",\"execId\":\"22550774606679263\",\"investAccount\":\"xtrinterbankinvest01\",\"productAccount\":\"xtrinterbankprod01\",\"assetAccount\":\"xtrinterbankasst01\",\"securityAccount\":\"111010032010000205011\",\"securityType\":\"4\",\"settlType\":\"1\",\"orderModel\":\"legs\",\"orderStatus\":\"8\",\"createdTime\":1598145974,\"createdDate\":\"20200824\",\"tradeDate\":\"20200824\",\"positionFlag\":1,\"price\":111.0,\"orderQty\":1.0E7,\"accumulatedExecQty\":1.0E7,\"lastQty\":1.0E7,\"finalFlag\":true,\"symbol\":\"13国债15\",\"side\":\"1\",\"orderVersion\":2,\"classType\":\"OrderBO\",\"messageId\":87350933198472267,\"uniqueKey\":\"-20200822-221116-188-quote-100002\",\"topicName\":\"order\",\"subject\":\"business/order/130015/B/xtrinterbanktra01/xtrinterbankat01\",\"publisherId\":\"oms-710-9577@168-61-73-136\",\"tenantId\":\"ficc\",\"extFields\":{\"quotaionType\":\"5\",\"clOrdId\":\"-20200822-221116-188-quote-100001\",\"marketIndicator\":\"4\",\"deliveryType\":\"0\",\"transcatTime\":\"1883635200\",\"quoteStaus\":\"16\",\"clearingMethod\":\"13\",\"execType\":\"F\",\"validUnitTime\":\"1883635200\"}}";

    String tableName = "__UT_TestMap";

    IMap map = instance.getMap(tableName);
    map.addIndex(new IndexConfig(IndexType.HASH,"orderId"));

    map.put("-20200822-221116-188-quote-100002",json);

    System.out.println(map.entrySet(Predicates.sql("side='1'")));

`条件正确,但结果为null,为什么?不添加索引时,查询结果正确.

` condition is correct,but result is null,why? when I not add index , the result of query is correct.

推荐答案

在您的 map.put 中,尝试将value子句从 json 更改为 new HazelcastJsonValue(json))

In your map.put, try changing the value clause from json to new HazelcastJsonValue(json))

您命名为 json 的变量实际上是一个字符串,因此它是形式为 Map< String,String> 的映射.

The variable you've named json is actually a String, so it's a map of form Map<String, String>.

Hazelcast不会在String内搜索字段,因为它不知道它包含任何形式的结构化数据.您将获得一个 IllegalOperationException ,用于发布的代码.

Hazelcast won't search inside a String for a field, because it won't know that it contains any form of structured data. You'll get an IllegalOperationException for the code posted.

如果您使用 new HazelcastJsonValue(json))作为条目的值,则会使其结构化,并且可以在字段上进行搜索(和索引).

If you use new HazelcastJsonValue(json)) for the entry's value, that makes it structured, and you can search (and index) on fields.

这篇关于为什么hazelcast无法使用imap和hazelcastjsonvalue查询不正确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆