1
votes

I have the following error:

412 no matching index found. recommended index is:
- kind: monthly_report
properties:
- name: belongs_to
- name: date_added

I am using Python 3.5, the datastore, and a remote Django project which is accessing the datastore through google-cloud API (google-cloud==0.24.0).

I ran the commands:

google cloud datastore cleanup-indexes index.yaml
google cloud datastore create-indexes index.yaml

The indexes are created:

index.yaml:

indexes:

- kind: history
  ancestor: no
  properties:
  - name: date_added
    direction: asc
  - name: address
    direction: asc

- kind: payment
  ancestor: no
  properties:
  - name: date_added
    direction: asc
  - name: belongs_to
  - name: order

- kind: monthly_report
  ancestor: no
  properties:
  - name: date_added
    direction: asc
  - name: status
  - name: belongs_to
    direction: asc

I make a query on kind payment with filters on date_added and belongs_to. It works.

However, in the same method, I make a query on kind monthly_report with filters on date_added and belongs to, and I get the error above.

What is the issue?

Update:

If I filter for one name it works, for multiple names it does not.

2

2 Answers

0
votes

Google app engine's datastore automatically creates indices whenever you make a query involving all the filters you used. It stores your table data in that index for you so that it serves it quickly. So, whenever you deploy you have update the new indices.

If you are deploying using appcfg then, appcfg.py -A <project-name> update_indexes .

Here the . is the path of your index.yaml file.

Whenever you get no matching index found or NeedIndexError or missing index error, the error also suggests which index is missing. So, you just have to put that suggested index into your index.yaml file and update your indices using above command.

In this case, add this missing index to index.yaml file.

- kind: monthly_report
  properties:
  - name: belongs_to
  - name: date_added

I hope this helps. For more information Datastore Indices

0
votes

It seems that the order counts, so I changed this:

- kind: monthly_report
  properties:
  - name: belongs_to
  - name: date_added

to this:

- kind: monthly_report
  properties:
  - name: date_added
  - name: belongs_to