0
votes

Here is my query:

select * from profiles where expr(profiles_index, '{ 
  filter: { 
    type: "date_range", 
    field: "age", 
    from: "1984/01/01", 
    to: "2010/01/01", 
    operation: "is_within" 
  } 
}');

Here is my table:

CREATE TABLE profiles (
    user_id timeuuid,
    age timestamp,
    PRIMARY KEY (user_id)
);

and my schema looks something like this:

CREATE CUSTOM INDEX profiles_index ON profiles ()
USING 'com.stratio.cassandra.lucene.Index'
WITH OPTIONS = {
    'refresh_seconds' : '60',
    'schema' : '{
        default_analyzer : "english",
        fields : {
            age                  : {type : "date",
                                    validated : true,
                                    pattern : "yyyy/MM/dd"
            }
        }
    }'
};

AND i'm getting this exception:

Traceback (most recent call last): File "/opt/apache-cassandra-3.0.3/bin/cqlsh.py", line 1249, in perform_simple_statement result = future.result() File "/opt/apache-cassandra-3.0.3/bin/../lib/cassandra-driver-internal-only-3.0.0-6af642d.zip/cassandra-driver-3.0.0-6af642d/cassandra/cluster.py", line 3122, in result raise self._final_exception ReadFailure: code=1300 [Replica(s) failed to execute read] message="Operation failed - received 0 responses and 1 failures" info={'failures': 1, 'received_responses': 0, 'required_responses': 1, 'consistency': 'ONE'}

Does anyone know why I might be getting this error?

2

2 Answers

2
votes

@user1019182 is totally right, "date_range" searches are intended to be used with data indexed with "date_range" mapper, which indexes time durations composed by a start and stop date using a spatial approach.

For searching simple dates inside a time duration you should use a "range" search:

select * from profiles where expr(profiles_index, '{ 
  filter: { 
    type: "range", 
    field: "age", 
    lower: "1984/01/01", 
    upper: "2010/01/01", 
    include_lower: true,
    include_upper:true 
  } 
}');

@mahendra-singh is wrong, cqlsh default timestamp format is not related to this.

1
votes

I needed to use a "Range" search, not a "Date Range" search. If you use a "Date Range" search, you better have used a "Date Range Mapper".