0

我有一个对数据存储执行查询的肥皂服务:

private final String KEY_NAME = "keyName";
private final String KEY_TYPE = "storedData";
private final String ENTITY_TYPE = "record";
private final String TEMP_ROW = "temperatura";
private final String HUM_ROW = "umidita";
private final String DATE_ROW = "date";
private DatastoreService dataStore;
private Key dataKey = KeyFactory.createKey(KEY_TYPE, KEY_NAME);
private final Query query = new Query(ENTITY_TYPE, dataKey).addSort(DATE_ROW,
    Query.SortDirection.ASCENDING);

@WebMethod
public int sendData(String temperatura, String umidita) {
    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyy HH:mm:ss");
    Date date = new Date();

    Entity record = new Entity(ENTITY_TYPE, dataKey);
    record.setProperty(TEMP_ROW, temperatura);
    record.setProperty(HUM_ROW, umidita);
    record.setProperty(DATE_ROW, date);
    dataStore = DatastoreServiceFactory.getDatastoreService();
    dataStore.put(record);  
    return 1;
}

我写了这个 index.yaml

indexes:
- kind: Record
  ancestor: yes
  properties:
      - name: temperatura
      - name: umidita
      - name: data
      direction: asc

但是当我尝试执行该查询时出现此错误:

com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.
The suggested index for this query is:
<datastore-index kind="Record" ancestor="true" source="manual">
    <property name="date" direction="asc"/>
</datastore-index>

与查询不匹配的 index.yaml 有什么问题?

4

1 回答 1

1

您定义的索引使用 3 个属性。您的查询仅使用一个索引,或者您将查询更改为使用索引中定义的 3 个属性,或者您在模型声明中定义要索引的日期字段。

于 2013-08-31T18:14:31.390 回答