创建一个有限的数据存储索引。

huangapple go评论83阅读模式
英文:

Create a limited datastore index

问题

我在我的GAE应用程序中有一个查询,看起来像这样:

datastore.NewQuery("item").Ancestor(fk).Order("-PubDate").Limit(10).Run(c)

为了使其工作,我需要一个按PubDate排序的项目索引;自动生成的索引如下所示:

  • kind: item
    ancestor: yes
    properties:

    • name: PubDate
      direction: desc

这个索引非常大(约4 GB),但由于Limit()调用,大部分都不会被访问。是否可能让索引只记住每个祖先的10个结果?

英文:

I have a query in my GAE app that looks like this:

datastore.NewQuery("item").Ancestor(fk).Order("-PubDate").Limit(10).Run(c)

In order for this to work I need an index of items ordered by PubDate; the autogenerated one looks like:

- kind: item
  ancestor: yes
  properties:
  - name: PubDate
    direction: desc

This index is pretty big (about 4 GB) but most of it will never be touched because of that Limit() call. Is it possible to have the index only remember 10 results for each ancestor?

答案1

得分: 1

同一种类型的两个实体可以具有相同的属性,但一个实体具有该属性的索引,而另一个实体没有索引。

Java运行时中的低级Datastore API允许应用程序决定是否为每个单独的实体索引每个属性。我不知道其他运行时是否存在等效的功能。如果没有,您可以使用两个不同的属性名称来表示索引日期和非索引日期。

因此,从技术上讲,您可以只在索引中保留少量实体。但请注意,您将需要重新保存一个具有未索引属性的实体,以将其从索引中删除。重新保存所有实体将产生额外的成本,因此,如果您无论如何都要为任何其他原因重新保存实体,这个解决方案可能是有意义的。

英文:

It is possible to have two entities of the same kind to have the same property, but one entity having this property indexed and the other unindexed.

The low-level Datastore API in Java runtime allows an app to decide whether to index or not each property for each individual entity. I don't know if an equivalent exists in other runtimes. If not, you can use two different property names to indicate an indexed date and unindexed date.

So technically, yes, you can keep only a small number of entities in the index. Note, however, that you will have to re-save an entity with a property unindexed in order to remove it from that index. Re-saving all entities will incur additional costs, so this solution probably makes sense if you re-save an entity anyway for any other reason.

huangapple
  • 本文由 发表于 2015年4月16日 05:32:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/29661317.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定