Kibana 我有2个索引,一个产品和其他品牌在ES,其中的产品有品牌ID在它和我试图获取品牌有产品

pbossiut  于 5个月前  发布在  Kibana
关注(0)|答案(1)|浏览(99)

我在ES中有2个索引,一个产品和其他品牌。产品中有brand_id,我试图获取有产品的品牌。但这是在ES 5.6中使用类型的早期。但在ES 7.10中,类型被删除,我们有2个单独的索引。我如何根据是否有产品来获取品牌

"bool": {
"must": [
{
"has_child": {
"type": "product",
"query": {
"term": {
"is_published": {
"value": 1,
"boost": 1
}
}
}
}
}
]
}
}

字符串

z4iuyo4d

z4iuyo4d1#

你必须把你的解决方案分为两部分,首先拉product brand IDs

GET /product/_search
    {
      "size": 0,
      "query": {
        "term": {
          "is_published": {
            "value": 1
          }
        }
      },
      "aggs": {
        "brand_ids": {
          "terms": {
            "field": "brand_id",
            "size": 1000
          }
        }
      }
    }

字符串
然后查询您的品牌索引以获取有关这些品牌的详细信息。

GET /brands/_search
{
  "query": {
    "terms": {
      "_id": [ /* this would be the list of brand_ids from Step 1 */ ]
    }
  }
}

相关问题