An example of creating a table containing a CQL collection set of famous
quotations.
In this example, you create a table containing a CQL collection set of famous
quotations. You insert data into the table by copy/pasting INSERT commands from a
file that you download. Download the INSERT commands in the
quotations.zip file now.
Next, you index the data in DSE Search/Solr, and finally, query the table using the
Solr HTTP API.
Procedure
-
If you did not already create a directory named solr_CQL3tutorial that contains
a schema.xml and solrconfig.xml, do so
now. Copy the schema.xml and
solrconfig.xml from the
demos/wikipedia directory to
solr_CQL3tutorial.
-
After starting DSE as a Solr
node, open a shell window or tab, go to the bin directory on Linux for
example, and start CQL:
-
Create a keyspace and a table consisting of a set collection column and other
columns, and then, insert some data for DSE Search to index.
CREATE KEYSPACE mykeyspace
WITH REPLICATION = {'class':'NetworkTopologyStrategy', 'Solr':1};
USE mykeyspace;
CREATE TABLE mysolr (
id text PRIMARY KEY,
name text,
title text,
quotes set <text>
);
-
Unzip the quotations.zip file that you downloaded, copy
the insert commands, and paste them on the cqlsh command line.
-
Change the schema.xml in the solr_CQL3tutorial directory
to contain this schema shown in the Sample schema section.
-
Create a search index using the cURL utility. On the operating system command line
in the solr_CQL3tutorial directory, post the
solrconfig.xml and the schema.xml,
and create a Solr core.
$curl http://localhost:8983/solr/resource/mykeyspace.mysolr/solrconfig.xml --data-binary @solrconfig.xml -H 'Content-type:text/xml; charset=utf-8'
$ curl http://localhost:8983/solr/resource/mykeyspace.mysolr/schema.xml --data-binary @schema.xml -H 'Content-type:text/xml; charset=utf-8'
$ curl "http://localhost:8983/solr/admin/cores?action=CREATE&name=mykeyspace.mysolr"
If you are recreating the mykeyspace.mysolr core, use the RELOAD instead of
the CREATE command.
-
Search Cassandra using the Solr HTTP API to find titles like Succ*.
http://localhost:8983/solr/mykeyspace.mysolr/
select?q=title%3ASucc*&wt=json&indent=on&omitHeader=on
{
"response":{"numFound":2,"start":0,"docs":[
{
"id":"126",
"title":"Success",
"quotes":["If A is success in life, then A equals x plus y
plus z. Work is x; y is play; and z is keeping your mouth
shut."],
"name":"Albert Einstein"},
{
"id":"125",
"title":"Success",
"quotes":["Always bear in mind that your own resolution to
succeed is more important than any one thing.",
"Better to remain silent and be thought a fool than to speak
out and remove all doubt."],
"name":"Abraham Lincoln"}]
}}