我正在使用Datastax Enterprise。我得到了例外:
com.datastax.driver.core.exceptions.InvalidQueryException:无法在非搜索节点上执行Solr查询。 at com.datastax.driver.core.exceptions.InvalidQueryException.copy(InvalidQueryException.java:50) 在com.datastax.driver.core.DriverThrowables.propagateCause(DriverThrowables.java:37) at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:245) 在com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:64) 在com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:39) 在com.example.cassandra.simple_client.App.main(App.java:98)
当我尝试运行以下内容时:
Cluster cluster = Cluster.builder()
.addContactPoint("104.236.160.56")
.addContactPoint("104.236.160.96")
.withRetryPolicy(DefaultRetryPolicy.INSTANCE)
.withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().build()))
.build();
Metadata metadata = cluster.getMetadata();
System.out.printf("Connected to cluster: %s\n", metadata.getClusterName());
for ( Host host : metadata.getAllHosts() )
System.out.printf("Datacenter: %s; Host: %s; Rack: %s; Dse version: %s; Cassandra version: %s\n", host.getDatacenter(), host.getAddress(), host.getRack(), host.getDseVersion(), host.getCassandraVersion());
try {
Session session = cluster.connect("rombie");
ResultSet result = session.execute("SELECT * FROM rombie.force WHERE solr_query='{\"q\":\"point:[ 30 TO *]\", \"sort\":\"point desc\"}' LIMIT 50 ALLOW FILTERING");
List<Row> list = result.all();
for (Row row : list)
System.out.println(row.getString("force_tag"));
} catch (Exception e) {
e.printStackTrace();
}
同一数据中心内的2个节点可以互相看到:
注意:如果我评论Cassandra节点它正在工作:104.236.160.56或使用普通查询而不是Solr查询