我想从Datastore返回myHighscores: 即:保罗,1200 汤姆,1000 凯文,800
private void returnHighscores(HttpServletResponse resp, String game, int max) throws IOException {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key gameKey = KeyFactory.createKey("game", game);
Query query = new Query("highscore", gameKey);
query.addSort("points", Query.SortDirection.DESCENDING);
List<Entity> highscores = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(max));
for(Entity e : highscores) {
resp.getWriter().println(e.getProperty("name") + "," + e.getProperty("points"));
}
}
但如果我尝试运行此操作,我会收到错误:
com.google.appengine.api.datastore.DatastoreNeedIndexException:找不到匹配的索引。此查询的建议索引是:
<datastore-index kind="highscore" ancestor="true" source="manual"> <property name="points" direction="desc"/> </datastore-index>
我该如何解决这个问题?