0
votes

I am writing a query for Google Cloud Datastore, wanting to find the entity with a certain "moduleID" and the highest number of "sessionID_tot".

$session_query = $datastore->query()
                        ->kind('Session')
                        ->filter('moduleID', '=', $module)
                        ->order('sessionID_tot', Query::ORDER_DESCENDING)
                        ->limit(1);
$session_result = $datastore->runQuery($session_query);

I get the following error.

{ "error": { "code": 400, "message": "no matching index found. recommended index is:\n- kind: Session\n properties:\n - name: moduleID\n - name: sessionID_tot\n direction: desc\n", "status": "FAILED_PRECONDITION" } }

I have read all the limitations on queries here, but can't seem to find a solution all the same. It works if I remove either the ordering or the filter for "moduleID". The properties I'm sorting and filtering are integers. Any ideas what I'm doing wrong?

1

1 Answers

1
votes

As mentioned in the error, and linked to from the page you referenced. You need to create a composite index for that query.