当我尝试在按日期排序的数据存储上运行查询时,出现以下错误:
NeedIndexError: no matching index found.
The suggested index for this query is:
- kind: Message
properties:
- name: author
- name: ref
- name: date
如果我不尝试按日期订购,则查询运行不会出错。数据存储索引下的 appengine 控制台说:
author ▲ , ref ▲ , date ▼
Serving
我究竟做错了什么?如何运行按日期排序的查询?谢谢!
这是我的实体定义:
from google.appengine.ext import ndb
class Message(ndb.Model):
subject = ndb.StringProperty()
body = ndb.TextProperty()
date = ndb.DateTimeProperty(auto_now_add=True)
ref = ndb.StringProperty( required=True )
author = ndb.KeyProperty(required=True)
这是失败的查询:
def readMessages( ref, user = None ):
query = Message.query()
query = query.filter(Message.ref == ref )
if user:
query = query.filter(Message.author == user.key )
query = query.order(Message.date)
# convert to a list so we can index like an array
return [ message for message in query ]
我的 index.yaml 包含:
indexes:
- kind: Message
properties:
- name: author
- name: ref
- name: date
direction: desc