I'm using GAE flexible environment, .Net, and Datastore. The issue I'm having is that I cannot figure out how to remove the index that Datastore automatically adds to every property of an Entity.
I know I can view the Entities on the GCP site and remove the index from there but it only removes the index for that specific Entity. Any knew Entities added will still index that property.
For some of the other supported languages there are attributes you can add to the class that will tell Datastore not to index that property. There must be a way to do this with .Net but I have not found it.
Here is a sample class:
public class MeetingRoom
{
[Key]
[Required]
public long Id { get; set; }
[Required]
public string Name { get; set; }
[DataType(DataType.MultilineText)]
public string Description { get; set; }
public ICollection<Notification> Notifications { get; set; }
}
Let's say the Notifications property will never be used in a query. So instead of paying the cost of having a child Entity for each Notification I simply JsonConvert the property and store it as a string.
The resulting Entity looks like this:
MeetingRoom room = GetMeetingRoom(34);
Entity entity = new Entity ()
{
Key = room.Id.ToKey(),
["Name"] = room.Name,
["Description"] = room.Description,
["Notifications"] = JsonConvert.SerializeObject(room.Notifications)
}
For this example, Notifications expire after a month and are removed from the list. Because of this, the Entity will never reach the 1MiB limit imposed by Datastore. However, because Notifications is an indexed string it is limitted to 1500 characters.
It's this 1500 character limit that I am banging up against. If I can figure out how to keep Datastore from indexing that property then I can live happily within the 1MiB Entity limit.
Can anyone help me with this?
Here is the solution as per the answer by @QuestionAndAnswer
In the Entity, setting the Value property's ExcludeFromIndexes
to true
will prevent the property from being indexed.
From my example above, the corrected Entity looks like this:
MeetingRoom room = GetMeetingRoom(34);
Entity entity = new Entity ()
{
Key = room.Id.ToKey(),
["Name"] = room.Name,
["Description"] = room.Description,
["Notifications"] = new Value()
{
StringValue = JsonConvert.SerializeObject(room.Notifications),
ExcludeFromIndexes = true
}
}
Looking at the example in documentation, you should pass ExcludeFromIndexes
on entity creation step.
https://cloud.google.com/datastore/docs/concepts/indexes#unindexed_properties