DataStax Enterprise 4.0

Example: Using a CQL collection set

In this example, you create a table containing a CQL collection set of famous quotations. You insert data into the table by copying/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

  1. 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.
  2. 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:
    ./cqlsh
  3. 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>
    );
  4. Unzip the quotations.zip file that you downloaded, copy the insert commands, and paste them on the cqlsh command line.
  5. Change the schema.xml in the solr_CQL3 tutorial directory to contain the schema shown in the Sample schema section.
  6. 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.
  7. 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"}]
    }}
Show/hide