Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started



Ryan Quey avatar image
Ryan Quey asked smadhavan edited

How can I run a solr_query in the Java driver mapper?

I want to use a query that uses solr_query in Java driver mapper.

I see that there is some support for search in the Java driver from here, but this page doesn't give a ton of details.

Besides just passing in a string to `session.execute`, how can I run a solr_query?

java driversearch
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

smadhavan avatar image
smadhavan answered smadhavan edited

@Ryan Quey, I understand you're running a DataStax Enterprise (DSE) cluster with Search workload enabled and wanted to execute queries involving the solr_query search index column of the table. I have provided an example demonstration of this functionality here. Please do accept this answer if this answers your question or update/comment if you've other additional questions.

TL;DR The key here is to leverage the Mapper & Query Methods to build the needed functionality. I have utilized version 4.9.0 in the above example demonstration. It is an end-to-end working example which creates the keyspace, table and sample data to demonstrate the select operation.

4 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

I tried your example and it works great thanks. Now I'm curious though because I was trying something similar but with a more complex solr query, and it wasn't working. I'll have to look at this more and see where I went wrong. Thanks for putting together this example

0 Likes 0 ·

Fantastic @Ryan Quey good to know!

0 Likes 0 ·

Question for you, will this work for Dao methods annotated by `@Select` instead of `@Query` as well? E.g., `@Select(customWhereClause = "solr_query = :solrQuery")`

0 Likes 0 ·

@Ryan Quey, that is absolutely possible to leverage `@Select` annotation's `customWhereClause` parameter to achieve the same thing!

p/s: It's great that you seemed to be experimenting/evaluating a wide variety of topics related to DataStax suite of products. Have you considered to leverage the DataStax Professional Services to help with your efforts?

1 Like 1 ·
Erick Ramirez avatar image
Erick Ramirez answered Ryan Quey commented

If you're asking about the CQL format when running a Solr query, you need to filter using solr_query. (Apologies if I misunderstood your question).

Here's an example CQL table with a Search index on the name column:

CREATE TABLE users_by_email (
    email text,
    name text,
    PRIMARY KEY (email)

Here's an example Solr query via CQL to find users named Alice & Bob but not Charlie:

SELECT ... FROM users WHERE solr_query='name:Alice name:Bob -name:Charlie'

For what it's worth, make sure that the driver is configured with a DSE Search data centre as the local DC.

Have a look at the DSE Search index enhancements CQL page for more details. Cheers!

1 comment Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thanks Erick, this time I was more wondering about other apis I could use besides just a CQL string, more like @smadhavan 's answer.

0 Likes 0 ·