title: How to fix index error when querying GAE datastore?
body: <p>When I try to run a query on the datastore ordered by date I get the following error:</p>
  
  <pre><code>NeedIndexError: no matching index found.
  The suggested index for this query is:
  
  - kind: Message
    properties:
    - name: author
    - name: ref
    - name: date
  </code></pre>
  
  <p>The query runs without error if I don't try to order by date. The appengine console under datastore indexes says:</p>
  
  <pre><code>author ▲ , ref ▲ , date ▼   
  Serving
  </code></pre>
  
  <p>What am I doing wrong? How can I run my query ordered by date? Thanks!</p>
  
  <p>Here is my entity definition:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>and this is the query that fails:</p>
  
  <pre><code>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 ]
  </code></pre>
  
  <p>My index.yaml contains:</p>
  
  <pre><code>indexes:
  
  - kind: Message
    properties:
    - name: author
    - name: ref
    - name: date
      direction: desc
  </code></pre>