Skip to content

PreconditionFailed: 412 no matching index found. when using inequality filters #1143

@sourcepirate

Description

@sourcepirate

I am using appengine to run my app and gcloud for accessing cloud datastore.
I have gcloud model where i am storing username and date_time attribute.

but when i am doing this.

from gcloud.datastore.query import Query
from datetime import datetime
query = Query(kind="MyTable")
query.add_filter('username', '=', 'somevalue')
query.add_filter('date_time', '<', datetime.now())

iterator = query.fetch(limit=10)
records, more, cursor = iterator.next_page()
print records

I am getting the following exception.

 File "/Users/sathyanarrayanan/Desktop/app/services/cdr_helper.py", line 528, in fetch_last_users
    records, more, cursor = iterator.next_page()
  File "/Users/sathyanarrayanan/Desktop/app/gcloud/datastore/query.py", line 388, in next_page
    transaction_id=transaction and transaction.id,
  File "/Users/sathyanarrayanan/Desktop/app/gcloud/datastore/connection.py", line 257, in run_query
    datastore_pb.RunQueryResponse)
  File "/Users/sathyanarrayanan/Desktop/app/gcloud/datastore/connection.py", line 108, in _rpc
    data=request_pb.SerializeToString())
  File "/Users/sathyanarrayanan/Desktop/app/gcloud/datastore/connection.py", line 85, in _request
    raise make_exception(headers, content, use_json=False)
PreconditionFailed: 412 no matching index found.

Below is my index file.

#File index.yaml

- kind: MyTable
  ancestor: yes
  properties:
  - name: date_time

- kind: MyTable
  ancestor: yes
  properties:
  - name: date_time
    direction: desc

- kind: MyTable
  ancestor: yes
  properties:
  - name: username
    direction: asc
  - name: date_time
    direction: desc

- kind: MyTable
  ancestor: yes
  properties:
  - name: username
    direction: asc
  - name: date_time

for more details: http://stackoverflow.com/questions/32607351/412-no-matching-index-found-while-executing-a-query-in-cloud-datastore

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: datastoreIssues related to the Datastore API.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions