我有一个在数据存储上执行查询的soap服务:
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与查询不匹配有什么问题?
答案 0 :(得分:1)
您定义的索引使用3个属性。您的查询仅使用一个索引,要么更改了查询以使用索引中定义的3个属性,要么在模型声明中定义要索引的日期字段。