栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

elasticsearch-将嵌套字段与文档中的另一个字段进行比较

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

elasticsearch-将嵌套字段与文档中的另一个字段进行比较

对于嵌套搜索,您要搜索没有父对象的嵌套对象。不幸的是,没有可以与

nested
对象一起应用的隐藏联接。

至少在当前,这意味着您不会在脚本中同时收到“父”文档和嵌套文档。您可以通过以下两种方式替换脚本并测试结果来确认这一点:

# Parent document does not exist"script": {  "script": "doc['primary_content_type_id'].value == 12"}# Nested document should exist"script": {  "script": "doc['content.content_type_id'].value == 12"}

可以
通过在

object
s上循环来以低于性能的方式执行此操作(而不是天生就让ES使用来为您执行此操作
nested
)。这意味着您必须将文档和
nested
文档重新索引为单个文档才能正常工作。考虑到您尝试使用它的方式,这可能并没有太大不同,甚至可能会表现得更好(特别是在缺少替代方法的情况下)。

# This assumes that your default scripting language is Groovy (default in 1.4)# Note1: "find" will loop across all of the values, but it will#  appropriately short circuit if it finds any!# Note2: It would be preferable to use doc throughout, but since we need the#  arrays (plural!) to be in the _same_ order, then we need to parse the#  _source. This inherently means that you must _store_ the _source, which#  is the default. Parsing the _source only happens on the first touch."script": {  "script": "_source.content.find { it.content_type_id == _source.primary_content_type_id && ! it.assigned } != null",  "_cache" : true}

我缓存的结果,因为没有动态发生在这里(例如,不比较日期

now
为实例),所以它是很安全的高速缓存,从而使未来的查找
快。默认情况下,大多数过滤器都是缓存的,但是脚本是少数例外之一。

由于 必须 比较两个值以确保找到正确的内部对象,因此您正在重复 一些
工作,但这实际上是不可避免的。拥有

term
过滤器最有可能胜过没有过滤器的情况。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/413579.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号