Cuong Thai
Cuong Thai

Reputation: 1165

No matching index found on DateTimeProperty Google App Engine

I'm using Google App Engine, Python and I'm building a feature that allows user to order their photos by the number of votes or creation_date.

The models should look like:

class MyUser(db.Model):
    user = db.UserProperty(required=True)
    name = db.StringProperty()
class UserImage(db.Model):
    user = db.ReferenceProperty(MyUser,collection_name='user_images')

    image_key = blobstore.BlobReferenceProperty(required=False)
    creation_date = db.DateTimeProperty(required=True,auto_now_add=True)
    votes = db.IntegerProperty(required=False)

Two queries I would like to run:

my_user = db.get('my_user_key')
1) image_keys = my_user.user_images.order('-votes').fetch(100,keys_only=True)
2) image_keys = my_user.user_images.order('-creation_date').fetch(100,keys_only=True)

The first query runs just fine but the second gives me NeedIndexError: no matching index found even when I add those properties into index.yaml

Here is my index.yaml

indexes:
- kind: UserImage
  properties:
  - name: user
  - name: votes
    direction: desc
  - name: creation_date
    direction: desc    

Google App Engine Dashboard tells me that all indexes are serving right now.


UPDATE

What I wrote in the index.yaml actually Order By votes then by creation_date. As suggested by dragonx. I split them out and it works as expected.


Thanks

Upvotes: 0

Views: 1375

Answers (1)

dragonx
dragonx

Reputation: 15143

Try separate indexes

indexes:
- kind: UserImage
  properties:
  - name: user
  - name: votes
    direction: desc

- kind: UserImage
  properties:
  - name: user
  - name: creation_date
    direction: desc    

Upvotes: 1

Related Questions