Hi,
I am trying a small query on geo data with my test installation (Ubuntu 3.7.3)
package de.schrell.aerospike.aerotest;
import com.aerospike.client.AerospikeClient;
import com.aerospike.client.AerospikeException;
import com.aerospike.client.Bin;
import com.aerospike.client.Key;
import com.aerospike.client.Record;
import com.aerospike.client.Value.GeoJSONValue;
import com.aerospike.client.policy.Policy;
import com.aerospike.client.policy.WritePolicy;
import com.aerospike.client.query.Filter;
import com.aerospike.client.query.IndexType;
import com.aerospike.client.query.RecordSet;
import com.aerospike.client.query.Statement;
import com.aerospike.client.task.IndexTask;
import java.util.UUID;
/**
* Hello world!
*
*/
public class App
{
public static void main( final String[] args )
{
System.out.println( "Hello Aerospike!" );
try (final AerospikeClient client = new AerospikeClient("localhost", 3000)) {
final Key key = new Key("test", "myset", UUID.randomUUID().toString());
final Bin bin = new Bin("mybin", new GeoJSONValue("{ \"type\": \"Point\", \"coordinates\": [50.0, 50.0] }"));
client.put(new WritePolicy(), key, bin);
System.out.println("creating index...");
createIndex(client);
System.out.println("created index.");
final Statement stm = new Statement();
stm.setNamespace("test");
stm.setSetName("myset");
stm.setFilters(Filter.geoWithinRadius("mybin", 50, 50, 100));
stm.setIndexName("geo");
System.out.println("XXXX");
try (final RecordSet rs = client.query(null, stm)) {
System.out.println("YYYYY");
while (rs.next()) {
System.out.println("ZZZZ");
final Key k = rs.getKey();
System.out.println("KEY: " + k);
final Record record = rs.getRecord();
System.out.println("REC: " + record);
final String geo = record.getGeoJSON("mybin");
System.out.println("GEO in Region: " + geo);
}
final String geo = client.get(new Policy(), key).getGeoJSON("mybin");
final GeoJSONValue g = new GeoJSONValue(geo);
System.out.println("GEO: " + geo);
}
}
}
// Doesn't complain if index is already there.
private static void createIndex(final AerospikeClient client) {
final Policy policy = new Policy();
policy.timeout = 0; // Do not timeout on index create.
final String binName = "mybin";
final String indexName = "geo";
try {
final IndexTask task = client.createIndex(policy, "test", "myset", indexName, binName, IndexType.GEO2DSPHERE);
task.waitTillComplete();
} catch (final AerospikeException e) {
e.printStackTrace();
}
}
}
at rs.next() I get an Error:
Hello Aerospike!
creating index...
created index.
XXXX
YYYYY
Exception in thread "main" com.aerospike.client.AerospikeException: Error Code 204: Index error
at com.aerospike.client.command.MultiCommand.parseGroup(MultiCommand.java:96)
at com.aerospike.client.command.MultiCommand.parseResult(MultiCommand.java:71)
at com.aerospike.client.command.SyncCommand.execute(SyncCommand.java:56)
at com.aerospike.client.query.QueryExecutor$QueryThread.run(QueryExecutor.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
I also created the index with aql, but that did not change anything. Also stm.setIndex(“geo”) did not matter.
Any hint, what I am doing wrong?
Andreas