How to retrieve the values from a query result
That query returns the data in the form of a json object. It’s possible to convert Value class to its primitive correspondent using to methods specifying a type.
What is it you’re trying to do? And where are you hitting difficulty?
The response to your query is a JSON object, which contains an array (in the data field), but is not itself an object. That’s why you’re getting that error: the object is not an array.
Given your query, and the sample response that you provided, if you wanted to list each titolo and autore field in the response, you could do something like this:
Value value = client.query(
Map(
Paginate(
Match(Index("all_titoli"))
),
Lambda("X", Get(Var("X")))
)
).get();
// Access the array of documents in the response
Collection<Value> allDocuments = value.at("data").asCollectionOf(Value.class).get();
// Create an iterator to iterate over the documents
Iterator<Value> iterator = allDocuments.iterator();
// Iterate over the documents
while (iterator.hasNext()) {
// acquire the current document from the iterator
Value current = iterator.next();
// access each field from the current document
String titolo = current.at("data", "titolo").to(String.class).get();
String autore = current.at("data", "autore").to(String.class).get();
// Print out the field values
System.out.println("titolo= " + titolo);
System.out.println("autore= " + autore);
}
When I run this, after setting up a database with data to match your sample response, I get: