我最近为VirtualBox下载了DataStax Enterprise沙箱VM,以便了解即将推出的项目的信息检索。数据存储堆栈对我来说是全新的,所以在尝试解决问题之前,我正尽力尽我最大努力学习。
沙箱环境:Centos 6.6 DSE 4.7.2
我们希望能够使用DataStax Java驱动程序使用solr_query机制执行CQL查询。如果我们无法使其发挥作用,我们将回到Solrj。
那么,关于我的问题;我生成了一个包含4个字段的小样本表(upc
,name
,brand
,description
),其中3个是Cassandra中主键的一部分。当我创建Solr Core并使用CQL插入数据时,我似乎没有问题使用Solr管理查询控制台搜索数据。不幸的是,当我尝试使用solr_query创建CQL语句时,我只能选择属于Cassandra主键的字段。如果我执行select *
或select description
(description
不是主键的一部分),然后我收到以下错误:
Undefined name ttl(description) in selection clause))
这是CQL:
select upc,name,brand,description from catalog.item
where solr_query = '{"q":"name:Milk*"}';
有趣的是,如果我使用token()
函数,我可以很好地得到结果集:
select upc,name,brand,description from catalog.item
where token(upc) >= -9223372036854775808 and token(upc) <= 9223372036854775807
and solr_query = '{"q":"name:Milk*"}';
我在将数据加载到Cassandra时尝试设置ttl,但这没有任何效果。我担心我对Cassandra,Solr和DSE的内部人员了解得太多,无法弄清楚这里发生了什么。我不想在所有查询中使用token()
函数。如果有人能指出我正确的方向来获得这些专栏,我将非常感激。
我在DataStax Sandbox VM上加载这些数据。我使用了维基百科示例中的solrconfig.xml,没有任何更改。
我的卡桑德拉表:
CREATE KEYSPACE catalog WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
USE catalog;
create table item (
upc INT,
name TEXT,
brand TEXT,
description TEXT,
PRIMARY KEY ((upc), name, brand)
);
我的schema.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<schema name="product_catalog" version="1.5">
<types>
<fieldType name="int" class="solr.TrieIntField"/>
<fieldType name="string" class="solr.StrField"/>
<fieldType name="text" class="solr.TextField">
<analyzer><tokenizer class="solr.StandardTokenizerFactory"/></analyzer>
</fieldType>
</types>
<fields>
<field name="upc" type="int" indexed="true" stored="true" docValues="true"/>
<field name="name" type="string" indexed="true" stored="true" docValues="true"/>
<field name="brand" type="string" indexed="true" stored="true" docValues="true"/>
<field name="description" type="text" indexed="true" stored="true"/>
</fields>
<uniqueKey>(upc,name,brand)</uniqueKey>
</schema>
一些虚拟数据:
insert into catalog.item (upc, name, brand, description)
values (1001, 'Milk', 'Local Company', 'The best local milk in the area.');
insert into catalog.item (upc, name, brand, description)
values (1002, 'The Other Milk', 'The Other Brand', 'The cheaper, but not local milk.');
insert into catalog.item (upc, name, brand, description)
values (1003, 'Milky Way', 'Mars', 'A chocolate, caramel candy bar.');
insert into catalog.item (upc, name, brand, description)
values (1004, 'Milk Dubs', 'Hersheys', 'Bit-size caramel pieces covered in chocolate.');
insert into catalog.item (upc, name, brand, description)
values (1005, 'Almond Joy', 'Mars', 'Creamy coconut wafers dipped in chocolate with an almond on top.');
insert into catalog.item (upc, name, brand, description)
values (1006, 'Almonds', 'The Almond Company', 'Salted roasted almonds.');
insert into catalog.item (upc, name, brand, description)
values (1007, 'Unsalted Almonds', 'The Almond Company', 'Plain roasted almonds.');