我试图创建一个可以修改我的分数的脚本。所以我做到了:
if (!(doc['score_mod'].empty)) {
_score * doc['score_mod'].value
}
但现在我有一个名为web_page
的类型,它没有score_mod
值,而且它是通过https://github.com/codelibs/elasticsearch-river-web生成的。因此,当它被接受治疗时,我无法将价值放在其中。
有没有办法可以为web_page
提供静态分数,或者让groovy脚本检查该值是否存在?
web_pages
结果的当前代码失败,但对于score_mod
值的结果,它可以正常运行
答案 0 :(得分:2)
您应该可以使用elvis运算符和<div class="leftbox">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div id="rightbox">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
快捷键运算符,如下所示:
?.
因此,如果_score * (doc['score_mod']?.value ?: 1)
为doc['score_mod']
,或null
为空(或为零或为空),则默认为value
(并将其乘以1
})