Elasticsearch - 复杂产品中独特的方面聚合

时间:2017-05-25 12:54:15

标签: elasticsearch aggregation facet

受到article的启发我试图为具有复杂产品数据结构的电子商务制作过滤器。(产品可能有很多具有自己功能的skus(文章)) 雇佣是一种映射

"mappings": {
  "product": {
    "properties": {
      "category_ids": {
        "type": "long"
      },
      "name": {
        "type": "text"
      },
      "create_datetime": {
        "type": "date"
      },
      "skus": {
        "type": "nested",
        "properties": {
          "price" : {
            "type" : "double"
          },
          "count": {
            "type": "long"
          },
          "options": {
            "type": "nested",
            "properties": {
              "feature_id": {
                "type": "long"
              },
              "feature_value_id": {
                "type": "long"
              }
            }
          }
        }
      }
    }
  }
}

以下是产品的示例

{
  "name": "some product name",
  "create_datetime": 1493899329,
  "category_ids": [
    851
  ],
  "skus": [
    {
      "price": 885,
      "count": 18,
      "options": [
        {
          "feature_id": "2",
          "feature_value_id": "90"
        },
        {
          "feature_id": "3",
          "feature_value_id": "102"
        },
        {
          "feature_id": "8",
          "feature_value_id": "596"
        },
        {
          "feature_id": "17",
          "feature_value_id": "23"
        },
        {
          "feature_id": "23",
          "feature_value_id": "900"
        },
        {
          "feature_id": "16",
          "feature_value_id": "368"
        },
        {
          "feature_id": "18",
          "feature_value_id": "773"
        }
      ]
    },
    {
      "price": 1006,
      "count": 0,
      "options": [
        {
          "feature_id": "2",
          "feature_value_id": "90"
        },
        {
          "feature_id": "3",
          "feature_value_id": "102"
        },
        {
          "feature_id": "8",
          "feature_value_id": "596"
        },
        {
          "feature_id": "17",
          "feature_value_id": "23"
        },
        {
          "feature_id": "23",
          "feature_value_id": "900"
        },
        {
          "feature_id": "16",
          "feature_value_id": "369"
        }
      ]
    }
  ]
}

这是一个聚合

"aggs": {
  "agg_facets": {
    "nested": {
      "path": "skus.options"
    },
    "aggs": {
      "feature_id": {
        "terms": {
          "field": "skus.options.feature_id"
        },
        "aggs": {
          "feature_value_id": {
            "terms": {
              "field": "skus.options.feature_value_id"
            }
          }
        }
      }
    }
  }
}

正如您所看到的,产品包含少量skus(Stock Keeping Units,实际上它们是产品的实例,分为产品页面(产品))。 例如,2 skus是相同的,(具有相同的颜色,材料,制造商但不同的尺寸)在这种情况下,产品由具有给定特征的2个skus组成。 实际上,目前的方法与magento相同。 example of a product

常见的是,2个不同的skus具有几乎相同的特征,但差异很小。 如上所述,聚合计算skus中的特征数量。

例如,我们有3个品牌为“A”的产品,每个产品都有3个相同品牌的skus,但尺寸不同。在这种情况下,将正确计算尺寸,但品牌“A”将聚合9次,但我们需要3次(产品没有重复)。

有没有办法解决这个问题?

0 个答案:

没有答案