【问题标题】:Filter elasticsearch parent document when all nested documents match term condition当所有嵌套文档都匹配术语条件时过滤弹性搜索父文档
【发布时间】:2015-04-01 18:44:59
【问题描述】:

我有一个包含嵌套文档的父文档:

parent_mapping = {
  _id: { path: "id" },
  properties: {
    id: { type: "integer" },
    content: { type: "string" },
...
    children: {
      type: "nested",
        properties: {
          id:             { type: "integer" },
          main_entry:     { type: "boolean" },
...

我想获取所有嵌套文档都将 main_entry 设置为“false”的所有父文档。

filter: {
    nested: {
      path: "entries",
      filter: {
        not: {
          term: { "entries.main_entry" => "true" }
        }
      }
    }
  }

这给了我所有拥有任何嵌套文档且 main_entry 设置为“false”的父母。

我正在努力排除嵌套子项且 main_entry 设置为“true”的结果。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    问题是过滤器没有将条件应用于所有嵌套条目;相反,它过滤掉了符合条件的 0 个条目的文档。我的同事指出,通过将否定移到嵌套过滤器之外,我可以获得我想要的结果。

          filter: {
            not: {
              nested: {
                path: "entries",
                filter: {
                  term: { "entries.main_entry" => "true" }
                }
              }
            }
          }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-10
      • 1970-01-01
      • 2021-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多