Reputation: 1531
I've encountered a strange situation while I'm using Google Cloud DataStore query.
Here's my code:
var cutoff = DateTime.UtcNow.AddDays(-30);
var query = new Query("message")
{
Filter = Filter.And(
Filter.Equal("type", type),
Filter.Equal("receiver", receiver),
Filter.Equal("sender", sender),
Filter.GreaterThanOrEqual("created", cutoff))
};
// type is integer, receiver and sender is string
The exception log shows below:
Grpc.Core.RpcException: Status(StatusCode=FailedPrecondition, Detail="no matching index found. recommended index is:
- kind: message
properties:
- name: receiver
- name: sender
- name: type
- name: created
")
I've checked several times that all of the properties are really exist.
Below shows why I call it strange:
When I remove the property created
it worked fine:
var query = new Query("message")
{
Filter = Filter.And(
Filter.Equal("type", type),
Filter.Equal("receiver", receiver),
Filter.Equal("sender", sender)
};
// works fine
That direct me to think about the property created
is the key point.
But when I use only created
, it worked fine however.
var query = new Query("message")
{
Filter = Filter.And(
Filter.GreaterThanOrEqual("created", cutoff))
};
// works fine too
I don't have a clue what's happening.
Any help will be appreciated.
Thanks for reading.
Upvotes: 0
Views: 365
Reputation: 1531
OK, I've solved the problem myself.
The message did show that I didn't create an index properly to DataStore.
Here is how to create and upload the index file(index.yaml).
After I reset the index, it works fine as I expect.
Upvotes: 2