【问题标题】:Elastic search collapse with nested object嵌套对象的弹性搜索折叠
【发布时间】:2021-09-28 11:21:53
【问题描述】:

我有一个弹性搜索索引

喜欢

{
  "title": "A",
  "comments": [ 
    {
      "id":    "1"
    },
    {
       "id":    "2"
    }
  ]
},
{
  "title": "B",
  "comments": [ 
    {
      "id":    "1"
    },
    {
       "id":    "3"
    }
  ]
},
{
  "title": "C",
  "comments": [ 
    {
      "id":    "7"
    },
    {
       "id":    "3"
    }
  ]
}

我要折叠的是由嵌套对象组成的组。在上面的 JSON 中,我想按 Id 分组。 所以输出会是这样的

hits:[{
  "title": "A",
  "comments": [ 
    {
      "id":    "1"
    },
    {
       "id":    "2"
    }
  ]
},
  inner_hits {[
    {
      "title": "A",
      "comments": [ 
        {
          "id":    "1"
        },
        {
          "id":    "2"
        }
      ]
    },
    {
      "title": "B",
      "comments": [ 
        {
          "id":    "1"
        },
        {
          "id":    "3"
        }
      ]
    }
  ]}
}]

基本上我需要基于嵌套对象属性的折叠基础。

试过了

/_search?track_total_hits=true
{
    "collapse": {
        "field": "comments.id",
        "inner_hits": {
            "name": "id",
            "size": 10
        },
        "max_concurrent_group_searches": 3
    }
}

但它总是只在内部点击中返回第一个对象

【问题讨论】:

    标签: json elasticsearch search elasticsearch-5


    【解决方案1】:

    在对象 comments 的映射中,您应该删除 nested 类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多