【发布时间】:2017-01-09 17:17:54
【问题描述】:
我的 Android 项目中有以下实体:
@Entity
public class Journey {
@Id
private Long id;
private Ref<User> driver;
@Index private Ref<Event> event;
private Long nbPlaces;
@Index private String departureTime;
private String destination;
@Index private String departureDate;
}
在我的端点上进行以下查询:
@ApiMethod(
name = "listJourneyByEvent",
path = "journeyByEvent",
httpMethod = ApiMethod.HttpMethod.GET)
public CollectionResponse<Journey> listJourneyByEvent(@Named("idEvent") Long idEvent, @Nullable @Named("cursor") String cursor, @Nullable @Named("limit") Integer limit) {
limit = limit == null ? DEFAULT_LIST_LIMIT : limit;
Key<Event> key = Key.create(Event.class, idEvent);
Query<Journey> query = ofy().load().type(Journey.class).filter("event", key).order("departureDate").limit(limit);
if (cursor != null) {
query = query.startAt(Cursor.fromWebSafeString(cursor));
}
QueryResultIterator<Journey> queryIterator = query.iterator();
List<Journey> journeyList = new ArrayList<Journey>(limit);
while (queryIterator.hasNext()) {
journeyList.add(queryIterator.next());
}
return CollectionResponse.<Journey>builder().setItems(journeyList).setNextPageToken(queryIterator.getCursor().toWebSafeString()).build();
}
但是当我执行该方法时,我收到以下错误:
E/ch.hevs.co_voituragefiesta.async.AsyncJourneyList: com.google.api.client.googleapis.json.GoogleJsonResponseException: 503 Service Unavailable
{
"code": 503,
"errors": [
{
"domain": "global",
"message": "com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found. recommended index is:\n- kind: Journey\n properties:\n - name: event\n - name: departureDate\n\nThe suggested index for this query is:\n <datastore-index kind=\"Journey\" ancestor=\"false\" source=\"manual\">\n <property name=\"event\" direction=\"asc\"/>\n <property name=\"departureDate\" direction=\"asc\"/>\n </datastore-index>\n\n",
"reason": "backendError"
}
],
"message": "com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found. recommended index is:\n- kind: Journey\n properties:\n - name: event\n - name: departureDate\n\nThe suggested index for this query is:\n <datastore-index kind=\"Journey\" ancestor=\"false\" source=\"manual\">\n <property name=\"event\" direction=\"asc\"/>\n <property name=\"departureDate\" direction=\"asc\"/>\n </datastore-index>\n\n"
}
我了解到 GAE 需要一些时间来生成索引,但我认为这不是问题。
我还读到我们不能在一个实体中拥有多个索引。这是真的吗?
谢谢
【问题讨论】:
标签: android google-app-engine indexing entity objectify