您不能从嵌套查询上下文访问根值。它们被索引为单独的文档。从文档中
嵌套子句“下移”到嵌套注释字段中。它 不再有权访问根文档中的字段,也 无法 访问任何其他嵌套文档中的字段。
您可以借助copy_to参数获得所需的结果。执行此操作的另一种方法是使用 include_in_parent 或 include_in_root,
但将来可能会不建议使用它们,并且由于嵌套类型的每个字段都将包含在根文档中,因此还会增加索引大小,因此在这种情况下
copy_to功能会更好。
这是一个样本索引
PUT nested_index{ "mappings": { "blogpost": { "properties": { "rootdate": { "type": "date" }, "copy_of_nested_date": { "type": "date" }, "comments": { "type": "nested", "properties": { "nested_date": { "type": "date", "copy_to": "copy_of_nested_date" } } } } } }}在这里, nested_date的 每个值 都 将被复制到 copy_of_nested_date,
因此copy_of_nested_date看起来类似于[1401055200000,1393801200000,1221542100000],然后您可以使用像这样的简单查询来获取结果。
{ "query": { "bool": { "filter": [ { "script": { "script": "doc['rootdate'].value < doc['copy_of_nested_date'].value" } } ] } }}您不必更改嵌套结构,但必须在添加到 发布dateCreated 之后重新 索引 文档
copy_to__



