google-cloud-ruby: Getting "no matching index found" when running example

=> #<Google::Cloud::Datastore::Dataset:0x000055fbec9d62f8 @service=Google::Cloud::Datastore::Service(project_name)>
[17] pry(main)> task = datastore.entity "Task", "sampleTask" do |t|
[17] pry(main)*   t["type"] = "Personal"  
[17] pry(main)*   t["done"] = false  
[17] pry(main)*   t["priority"] = 4  
[17] pry(main)*   t["description"] = "Learn Cloud Datastore"  
[17] pry(main)* end  
=> #<Google::Cloud::Datastore::Entity:0x000055fbec7c39c0
 @_exclude_indexes={},
 @key=#<Google::Cloud::Datastore::Key:0x000055fbec7c3600 @kind="Task", @name="sampleTask", @namespace=nil, @project=nil>,
 @properties=
  #<Google::Cloud::Datastore::Properties:0x000055fbec7c3998
   @hash={"type"=>"Personal", "done"=>false, "priority"=>4, "description"=>"Learn Cloud Datastore"}>>
[18] pry(main)> 
[19] pry(main)> # Save the new task
[20] pry(main)> datastore.save task
=> [#<Google::Cloud::Datastore::Entity:0x000055fbec7c39c0
  @_exclude_indexes={},
  @key=#<Google::Cloud::Datastore::Key:0x000055fbec7c3600 @kind="Task", @name="sampleTask", @namespace=nil, @project=nil>,
  @properties=
   #<Google::Cloud::Datastore::Properties:0x000055fbec7c3998
    @hash={"type"=>"Personal", "done"=>false, "priority"=>4, "description"=>"Learn Cloud Datastore"}>>]
[21] pry(main)> 
[22] pry(main)> # Run a query for all completed tasks
[23] pry(main)> query = datastore.query("Task").
[23] pry(main)* where("done", "=", false)  
=> #<Google::Cloud::Datastore::Query:0x000055fbec4eb0b8
 @grpc=
  <Google::Datastore::V1::Query: projection: [], kind: [<Google::Datastore::V1::KindExpression: name: "Task">], filter: <Google::Datastore::V1::Filter: composite_filter: <Google::Datastore::V1::CompositeFilter: op: :AND, filters: [<Google::Datastore::V1::Filter: composite_filter: nil, property_filter: <Google::Datastore::V1::PropertyFilter: property: <Google::Datastore::V1::PropertyReference: name: "done">, op: :EQUAL, value: <Google::Datastore::V1::Value: boolean_value: false, integer_value: 0, double_value: 0.0, key_value: nil, entity_value: nil, geo_point_value: nil, array_value: nil, timestamp_value: nil, null_value: :NULL_VALUE, meaning: 0, string_value: "", blob_value: "", exclude_from_indexes: false>>>]>, property_filter: nil>, order: [], distinct_on: [], start_cursor: "", end_cursor: "", offset: 0, limit: nil>>
[24] pry(main)> tasks = datastore.run query
Google::Cloud::FailedPreconditionError: 9:no matching index found.
from /home/user/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/google-cloud-datastore-1.4.0/lib/google/cloud/datastore/service.rb:191:in `rescue in execute'```

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 21 (13 by maintainers)

Most upvoted comments

We found this lib and are giving it a try: https://github.com/firebase/firebase-admin-go You can probably chock this up to bad assumptions on our part. And the fact that this library partially works with Firestore (inserts, queries without filters, etc) which added to the confusion.

Databases created through Firebase create Cloud Firestore projects. Cloud Firestore and Cloud Datastore have some interoperability, however they have different query semantics (and thus different indexes). Like Cloud Datastore, Cloud Firestore has automatic indexes, but they are a different set of indexes, which is why your Cloud Datastore queries (with Cloud Datastore semantics) are missing an index.

If you want to use Cloud Firestore, you should use it with the Cloud Firestore client libraries. Otherwise, if you want to use Cloud Datastore client libraries, you should make sure to create a Cloud Datastore project at cloud.google.com/console.

Seems like we found the root of the issue.