CompanyNovember 28, 2016

JSON and DSE Search

Berenguer Blasi
Berenguer Blasi
JSON and DSE Search
CREATE KEYSPACE jsondemo WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
USE jsondemo;
create type jsondemo.trip (
origin text,
dest text,
);
create table jsondemo.holidays (
  "id" VARCHAR PRIMARY KEY,
  "title" TEXT,
  "season" TEXT,
  "date" date,
  "trips" list<frozen<trip>>);
dsetool create_core jsondemo.holidays generateResources=true
cqlsh> insert into jsondemo.holidays JSON '{"id":"1", "title":"First holiday ever", "season": "Xmas"}';
cqlsh> select * from jsondemo.holidays where solr_query='*:*';
 id | date | season | solr_query | title              | trips
----+------+--------+------------+--------------------+-------
  1 | null |   Xmas |       null | First holiday ever |  null
(1 rows)
cqlsh> insert into jsondemo.holidays (id, title, season, trips) values ('2', 'Week in Barcelona', 'Easter', [{origin: 'London', dest:'Barcelona'}, {origin: 'Barcelona', dest:'London'}]);
cqlsh> select * from jsondemo.holidays where solr_query='*:*';
 id | date | season | solr_query | title              | trips
----+------+--------+------------+--------------------+--------------------------------------------------------------------------------
  1 | null |   Xmas |       null | First holiday ever |                                                                           null
  2 | null | Easter |       null |  Week in Barcelona | [{origin: 'London', dest: 'Barcelona'}, {origin: 'Barcelona', dest: 'London'}]
(2 rows)
cqlsh> insert into jsondemo.holidays JSON '{"id":"3", "title":"Week in Miami", "season": "Summer holidays", "trips": [{"origin": "Barcelona", "dest": "Miami"}, {"origin": "Miami", "dest": "Barcelona"}]}';
cqlsh> select * from jsondemo.holidays where solr_query='*:*';
 id | date | season          | solr_query | title              | trips
----+------+-----------------+------------+--------------------+--------------------------------------------------------------------------------
  1 | null |            Xmas |       null | First holiday ever |                                                                           null
  2 | null |          Easter |       null |  Week in Barcelona | [{origin: 'London', dest: 'Barcelona'}, {origin: 'Barcelona', dest: 'London'}]
  3 | null | Summer holidays |       null |      Week in Miami |   [{origin: 'Barcelona', dest: 'Miami'}, {origin: 'Miami', dest: 'Barcelona'}]
(3 rows)
cqlsh> select json * from jsondemo.holidays where solr_query='*:*';
 [json]
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                                       {"id": "1", "date": null, "season": "Xmas", "solr_query": null, "title": "First holiday ever", "trips": null}
    {"id": "2", "date": null, "season": "Easter", "solr_query": null, "title": "Week in Barcelona", "trips": [{"origin": "London", "dest": "Barcelona"}, {"origin": "Barcelona", "dest": "London"}]}
 {"id": "3", "date": null, "season": "Summer holidays", "solr_query": null, "title": "Week in Miami", "trips": [{"origin": "Barcelona", "dest": "Miami"}, {"origin": "Miami", "dest": "Barcelona"}]}
(3 rows)
Discover more
DSE Search
Share

One-stop Data API for Production GenAI

Astra DB gives JavaScript developers a complete data API and out-of-the-box integrations that make it easier to build production RAG apps with high relevancy and low latency.