[英]Elasticsearch query to check date range not in date array
I have a 'reservations' field which stores an array of dates that an item has been reserved for. 我有一个“保留”字段,其中存储了已为某项保留的日期的数组。
Sample data: 样本数据:
{
reservations: [ "05/03/2015",
"05/04/2015",
"05/05/2015",
"05/18/2015",
"05/19/2015"
]
}
I'd like to search for a date range in elastic search and return all items that do not contain dates falling on these dates. 我想在弹性搜索中搜索日期范围,并返回所有不包含这些日期上的日期的项目。
So I have a startDate
and endDate
parameter to search for. 所以我有一个startDate
和endDate
参数来搜索。 However, the date range filter for elasticsearch will not fit this requirement. 但是,elasticsearch的日期范围过滤器不符合此要求。 Can I do this in some other way? 我可以用其他方式做到吗?
EDIT: 编辑:
I think the Date Range filter wont work because you can only compare the startDate
and endDate
with gte
or lt
to just ONE value on the right. 我认为“日期范围”过滤器将无法工作,因为您只能将带有gte
或lt
的startDate
和endDate
与右侧的一个值进行比较。 I basically have a bunch of dates on the left (start/end date range) that I need to check against and bunch of dates on the right (the multiple reservation dates). 我基本上需要在左边查看一堆日期(开始/结束日期范围),而在右边查看一堆日期(多个预订日期)。
This problem can be solved by using nested object. 通过使用嵌套对象可以解决此问题。 Convert reservations as a nested object to the main document and than range queries will work. 将保留作为嵌套对象转换到主文档,然后范围查询将起作用。
Example 例
{
reservation : [
{"thedate" : "2015-01-01"},
{"thedate" : "2015-03-12"},
...
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.