elasticsearch的衰减函数decay的日期类型参数

编程入门 行业动态 更新时间:2024-10-15 02:32:24

elasticsearch的衰减<a href=https://www.elefans.com/category/jswz/34/1771370.html style=函数decay的日期类型参数"/>

elasticsearch的衰减函数decay的日期类型参数

使用elasticsearch进行检索的时候有一个需求,距离现在越近的结果评分越高。决定采用function_score中的衰减函数gauss。
检索条件如下:

{"window_size": 20,"query": {"rescore_query": {"function_score": {"boost": 4,"functions": [{"gauss": {"date": {"origin": "2020-05-22","offset": "2y","scale": "6y"}},"weight": 4}]}}}}

offset和scale的时间单位想要使用月或者年,结果报错如下:

"caused_by": {"type": "illegal_argument_exception","reason": "failed to parse setting [DecayFunctionParser.scale] with value [6y] as a time value: unit is missing or unrecognized","caused_by": {"type": "illegal_argument_exception","reason": "failed to parse setting [DecayFunctionParser.scale] with value [6y] as a time value: unit is missing or unrecognized"}}

官网手册和其他网站搜了半天也没有资料介绍如何设置单位为年或者月,最后在源码找到原因了,它就是不支持年或者月,最长的单位是天。
源码此处的枚举如下:

final String normalized = sValue.toLowerCase(Locale.ROOT).trim();if (normalized.endsWith("nanos")) {return new TimeValue(parse(sValue, normalized, "nanos", settingName), TimeUnit.NANOSECONDS);} else if (normalized.endsWith("micros")) {return new TimeValue(parse(sValue, normalized, "micros", settingName), TimeUnit.MICROSECONDS);} else if (normalized.endsWith("ms")) {return new TimeValue(parse(sValue, normalized, "ms", settingName), TimeUnit.MILLISECONDS);} else if (normalized.endsWith("s")) {return new TimeValue(parse(sValue, normalized, "s", settingName), TimeUnit.SECONDS);} else if (sValue.endsWith("m")) {// parsing minutes should be case-sensitive as 'M' means "months", not "minutes"; this is the only special case.return new TimeValue(parse(sValue, normalized, "m", settingName), TimeUnit.MINUTES);} else if (normalized.endsWith("h")) {return new TimeValue(parse(sValue, normalized, "h", settingName), TimeUnit.HOURS);} else if (normalized.endsWith("d")) {return new TimeValue(parse(sValue, normalized, "d", settingName), TimeUnit.DAYS);} else if (normalized.matches("-0*1")) {return TimeValue.MINUS_ONE;} else if (normalized.matches("0+")) {return TimeValue.ZERO;} else {// Missing units:throw new IllegalArgumentException("failed to parse setting [" + settingName + "] with value [" + sValue +"] as a time value: unit is missing or unrecognized");}

附上源码地址

更多推荐

elasticsearch的衰减函数decay的日期类型参数

本文发布于:2024-03-13 19:29:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1734654.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   参数   日期   类型   elasticsearch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!