将 String 与 DateTimeOffset 用于日期值时的 Azure 搜索性能

Azure Search performance when using String vs DateTimeOffset for date values

比较过滤器(即:介于、大于、小于等)在(格式化为)字符串属性上的执行速度是否与针对特定数据类型 (DateTimeOffset) 时一样快?

例如,如果我想检索在 2011-05-12 之后修改过的文档,modifiedDateTime gt 2011-05-12T12:44:57.201Z where modifiedDateTime is DateTimeOffset 会比 [=13= 执行得更好吗? ] 其中 modifiedDateTimeString 是 String 类型字段?

是否有任何特定于 DateTimeOffset 的数据类型的 azure 搜索功能?

简短的回答是 Azure 搜索中的字符串范围比较不受官方支持,因此您应该使用 Edm.DateTimeOffset 来保存 date/time 信息。

较长的答案是,字符串范围比较会起作用,但只能在 lambda 的上下文之外(anyall)。这是一个偶然的特性,我们决定不删除以防万一有人使用它,但我们也决定不做广告,因为它只能在 lambda 表达式之外工作这一事实可能会造成混淆。

如果您希望 Azure 搜索支持 $filter 语法中字符串的范围比较,请在 User Voice 上添加建议。

假设您可以接受范围比较的功能限制,那么仍然有性能问题需要回答。这不是我们的基准测试,但我们可以推测一下。

在幕后,Edm.DateTimeOffset 存储在倒排索引中,作为自纪元以来的毫秒数。在 Lucene 术语中,使用 NumericRangeQuery instead of TermRangeQuery. Numeric fields are indexed using tries, which speeds up query performance versus the equivalent term range query. The Lucene documentation 查询它们是一个很好的起点,如果您有兴趣深入了解它是如何工作的。

And is there any azure search feature that is data-type specific to DateTimeOffset?

是的。仅适用于 DateTimeOffset 字段的 freshness scoring function requires a DateTimeOffset field, and there are certain options for interval faceting(日、月、年等)。