简体   繁体   English

ElasticSearch - 在无痛脚本过滤器中访问 date_range 数组

[英]ElasticSearch - Access array of date_range in painless script filter

Is there any way to access an array of date_range in a painless script filter?有没有办法在无痛脚本过滤器中访问 date_range 数组?

My mapping for the "blocked_dates" field is as follows:我对“blocked_dates”字段的映射如下:

"blocked_dates": {
    "type": "date_range",
    "format": "strict_date"
},

Data looks like this:数据如下所示:

"blocked_dates": [
    {
        "gte": "2019-07-12",
        "lte": "2019-07-14"
    },
    {
        "gte": "2019-07-16",
        "lte": "2019-07-18"
    }
],

I am using Amazon ElasticSearch v6.7 so I cannot use params._source in a script filter and if I try and access it via doc then I get an illegal_argument_exception.我正在使用 Amazon ElasticSearch v6.7,因此我无法在脚本过滤器中使用 params._source,如果我尝试通过 doc 访问它,则会收到非法参数异常。

"blocked_dates = doc['blocked_dates'].value; ",
"                    ^---- HERE"

Fielddata is not supported on field [blocked_dates] of type [date_range] [date_range] 类型的字段 [blocked_dates] 不支持字段数据

I have a complex booking window requirement that checks if the chosen move-in and move-out date is within x days of another booking (blocked date) and this has to be done in a script.我有一个复杂的预订窗口要求,检查所选的入住和搬出日期是否在另一个预订的 x 天内(锁定日期),这必须在脚本中完成。

I could do something hacky like store a copy of the array of date_range as a comma delimited (ie "2019-07-20,2019-09-12") string array.可以做一些骇人听闻的事情,例如将 date_range 数组的副本存储为逗号分隔(即“2019-07-20,2019-09-12”)字符串数组。 Then grab the string array from the painless script filter and parse the dates out of them.然后从无痛脚本过滤器中获取字符串数组并从中解析出日期。

But that is my last resort.但这是我最后的手段。

Try params._source.blocked_dates.gte (or lte depends on your needs), but keep in mind what it returned string, but not a date in your particular case.尝试params._source.blocked_dates.gte (或lte取决于您的需要),但请记住它返回的字符串,但不是您特定情况下的日期。

In my case (float_range) solution was在我的情况下 (float_range) 解决方案是

"script": {
  "lang": "painless",
  "source": "Float.parseFloat(params._source.price.gte)"
}

I think idea is pretty clear我认为想法很清楚

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM