Opensearch DSL - Find records with field not equals each other - dsl

Is it possible to query records that has two field not equals each others?
For example:
SELECT * FROM <index> WHERE FIELD1!=FIELD2;

Related

Can ARRAY_CONTAINS accept multiple values in Cosmos

Do you have sample if i want to match multiple values of one attribute in Array_contains
select * from c where c.sid="1" and c.unum=39 and ARRAY_CONTAINS (c.dcodes,"DIST,DEFT")
where dcodes is my array having just list of codes in my document. so i want to pull all the records for the dcodes i passed into the query it may be one or many.
You're currently just passing a single string. You need to pass an array of values as your first parameter to ARRAY_CONTAINS(). So in your case, if you wanted to select all documents whose property c.dcodes contains either "DIST" or "DEFT", you'd need to do something like:
SELECT *
FROM c
WHERE c.sid="1" and c.unum=39
AND ARRAY_CONTAINS (["DIST","DEFT"],c.dcodes)

how Cql's Collection contains alternative value?

I have a question to query to cassandra collection.
I want to make a query that work with collection search.
CREATE TABLE rd_db.test1 (
testcol3 frozen<set<text>> PRIMARY KEY,
testcol1 text,
testcol2 int
)
table structure is this...
and
this is the table contents.
in this situation, I want to make a cql query has alternative option values on set column.
if it is sql and testcol3 isn't collection,
select * from rd.db.test1 where testcol3 = 4 or testcol3 = 5
but it is cql and collection.. I try
select * from test1 where testcol3 contains '4' OR testcol3 contains '5' ALLOW FILTERING ;
select * from test1 where testcol3 IN ('4','5') ALLOW FILTERING ;
but this two query didn't work...
please help...
This won't work for you for multiple reasons:
there is no OR operation in CQL
you can do only full match on the value of partition key (testcol3)
although you may create secondary indexes for fields with collection type, it's impossible to create an index for values of partition key
You need to change data model, but you need to know the queries that you're executing in advance. From brief looking into your data model, I would suggest to rollout the set field into multiple rows, with individual fields corresponding individual partitions.
But I want to suggest to take DS201 & DS220 courses on DataStax Academy site for better understanding how Cassandra works, and how to model data for it.

Cassandra Range Query : Secondary Index vs Unindexed Colum

I have seen that the best way to do range query on cassandra is by using CLUSTERING KEY. But I need to do some range query other than CLUSTERING KEY columns.
I read that we can do it on any column using ALLOW FILTERING. But is there any performance advantage if I create secondary index on that column ?
Have a look at this link:
https://www.datastax.com/dev/blog/allow-filtering-explained-2
The ALLOW FILTERING option allows you tell Cassandra that it is ok to perform in-memory filtering of the data once it loads rows from disk. So we can use this to search by a clustering column without specifying the previous clustering columns. But we can't use it on non-clustering columns.
See the below example schema from the blog. Use of ALLOW FILTERING doesn't allow us to filter by author column until we make it an index, which then doesn't need the ALLOW FILTERING option.
cqlsh:test> SELECT * FROM blogs WHERE author = 'john' ALLOW FILTERING;
Bad Request: No indexed columns present in by-columns clause with Equal operator
cqlsh:test>
cqlsh:test> CREATE INDEX authors ON blogs (author);
cqlsh:test> SELECT * FROM blogs WHERE author = 'john';
(0 rows)
cqlsh:test> SELECT * FROM blogs WHERE author = 'john' ALLOW FILTERING;
(0 rows)

Can we filter Columns in Select query using Datastax Accessor?

With Datastax java driver for cassandrausing #Accessor for select query, Can we filter columns in query itself instead of select * always
All the examples and docs I see select all the columns.
For example
Select column_A from table
As stated in this example you have query under your hand. There is a * and you can change it to whatever you like. So you can change * to column_A only but pay attention that class under mapping must have same structure. Of course it must be valid CQL query with all partition and clustering columns.
So let's say that you need only first_name of User class. You would create User class with only first_name property and Accessor which is using mapped class under the hood will map only first_name property and you will get list of User objects with single property.
Good way to do it if you sometimes need full object and sometimes only handful of properties would be to create some kind of light mapper objects with subset of properties and use it where needed.

CQL and range on secondary indexed columns

The below CQL query resulted in an error saying
No indexed columns present in by-columns clause with equals operator
Note that the column age was already secondary indexed.
select * from employee where age > 25
However I had another secondary indexed column type. So when I used that...
select * from employee where type='engineer' and age > 25
I seemed to get proper results.
How does this happen?
Cassandra's built-in secondary indexes are more of a hash-style index, as opposed to a B-tree.
As such, at least one equality comparison is required to perform lookups efficiently (any additional column predicates result in late-filtering of the equality matches).
Try the following wiki page for a decent starting point for questions about Cassandra's secondary indexes: http://wiki.apache.org/cassandra/SecondaryIndexes

Resources