从Stratio Lucene Index插件的文档中,INet映射器看起来很有趣,但背后并没有很多动机:即。 https://github.com/Stratio/cassandra-lucene-index/blob/branch-3.0.9/doc/documentation.rst#inet-mapper
鉴于它代表一个IP地址(打字),因此不同于简单的字符串,我可以应用哪种查询?特别是,是否可以对其进行远程查询?
答案 0 :(得分:1)
Lucene index inet mapper旨在映射CQL inet数据类型。它的唯一优势是使解析更灵活。例如,给出以下数据:
CREATE TABLE t (
pk int PRIMARY KEY,
address inet
) ;
CREATE CUSTOM INDEX i ON t ()
USING 'com.stratio.cassandra.lucene.Index'
WITH OPTIONS = {
'refresh_seconds': '1',
'schema': '{
fields : {
address : {type: "inet"},
address_s : {type: "string", column: "address"}
}
}'};
INSERT INTO t(pk, address) VALUES (0, '::FFFF:8:8:8');
所有这些查询都会找到索引行:
SELECT * FROM t WHERE expr(i, '{filter:{type:"match", field:"address", value: "::ffFF:8:8:8"}}');
SELECT * FROM t WHERE expr(i, '{filter:{type:"match", field:"address", value: "::0:ffff:8:8:8"}}');
SELECT * FROM t WHERE expr(i, '{filter:{type:"match", field:"address", value: "0:0:0:0:ffff:8:8:8"}}');
但是,相同的查询不适用于字符串映射器:
SELECT * FROM t WHERE expr(i, '{filter:{type:"match", field:"address_s", value: "::ffFF:8:8:8"}}');
SELECT * FROM t WHERE expr(i, '{filter:{type:"match", field:"address_s", value: "::0:ffff:8:8:8"}}');
SELECT * FROM t WHERE expr(i, '{filter:{type:"match", field:"address_s", value: "0:0:0:0:ffff:8:8:8"}}');
SELECT * FROM t WHERE expr(i, '{filter:{type:"wildcard", field:"address_s", value: "*:8:8:8"}}');
除此之外,生成的Lucene字段是字符串字段,因此对通配符或范围查询没有特殊处理,应使用IP地址的扩展格式并具有字典行为:
SELECT * FROM t WHERE expr(i, '{filter:{type:"wildcard", field:"address", value: "*:8:8:8"}}');
SELECT * FROM t WHERE expr(i, '{filter:{type:"range", field:"address", lower: "::FFFF:8:8:7"}}');