Filtering queries with the solr_query q format

Filter a CQL query using solr_query option using the syntax of the Solr q parameter in plain text. See Filtering on terms for examples.

solr_query = '<q_expression>'

Examples

Filtering on a single column

To find rows in the pets table where the name column contains cat, dog but not fish:

SELECT * FROM pets WHERE solr_query='name: cat name: dog -name:fish';

To use punctuation such as a single quote in the Solr q expression, see Escaping characters in a solr_query.

Limiting results

When you name specific columns, DSE Search retrieves only the specified columns and returns the columns as part of the resulting rows. DSE Search supports projections (SELECT a, b, c…​) only, not functions, for the select expression. The following example retrieves only the name column:

SELECT name FROM keyspace.table WHERE solr_query='name:cat name:dog -name:fish'

Use the LIMIT clause to specify how many rows to return. The following example retrieves only 1 row:

SELECT * FROM keyspace.table WHERE solr_query='name:cat name:dog -name:fish' LIMIT 1

Using the count function

Use the count() function in CQL Solr queries to return the number of rows that satisfy the Solr query:

SELECT count(*) FROM table WHERE solr_query = '...';

Using count() in combination with LIMIT or facets results in an error.

All response queries of the drivers have a custom payload where the total number of documents found is returned. This number is keyed as DSESearch.numFound.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com