Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datastore: Filtering with equality fails with FailedPrecondition desc = no matching index found #930

Closed
lc-chrisbarton opened this issue Mar 9, 2018 · 2 comments
Assignees

Comments

@lc-chrisbarton
Copy link

lc-chrisbarton commented Mar 9, 2018

According to the docs:

https://cloud.google.com/datastore/docs/concepts/queries#datastore-equal-and-inequality-range-go
"Note that a query can combine equality (EQUAL) filters for different properties, along with one or more inequality filters on a single property. Thus the following is a valid query:"

query := datastore.NewQuery("Task").
    Filter("Priority =", 4).
    Filter("Done =", false).
    Filter("Created >", time.Date(1990, 1, 1, 0, 0, 0, 0, time.UTC)).
    Filter("Created <", time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC))

However when I create the simple table in the attached screenshot the following code from the docs fails:

q := datastore.NewQuery("Task").Namespace("test").
	Filter("Priority =", 4).
	Filter("Done =", false).
	Filter("Created >", time.Date(1990, 1, 1, 0, 0, 0, 0, time.UTC)).
	Filter("Created <", time.Date(2018, 3, 9, 0, 0, 0, 0, time.UTC))

var t []*task
if _, err := datastoreClient.GetAll(ctx, q, &t); err != nil {
	log.Printf("Failed reading: %v", err)
}

Error is:

2018/03/10 09:24:16 Failed reading: rpc error: code = FailedPrecondition desc = no matching index 
found. recommended index is:
- kind: Task
  properties:
  - name: Done
  - name: Priority
  - name: Created

screen shot 2018-03-10 at 9 21 59 am

@jba
Copy link
Contributor

jba commented Mar 9, 2018

I think you'll need to define an index for that query. See https://cloud.google.com/datastore/docs/concepts/indexes#index_configuration.

@lc-chrisbarton
Copy link
Author

Thanks very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants