【问题标题】:Faceted search in webshop with Elastic使用 Elastic 在网上商店中进行分面搜索
【发布时间】:2017-10-18 09:53:05
【问题描述】:

我在 Elastic 中看到了一些关于分面搜索的示例,但他们都事先知道您希望创建存储桶的字段。

当我的网上商店有多个类别,每个类别的值属性都不同时,我应该如何工作?

有没有一种方法可以在您运行查询时描述您的文档具有哪些属性(例如按类别过滤)?

我现在有这个问题:

{
   "from" : 0, "size" : 10,
   "query": {
        "bool" : {
            "must" : [
              { "terms": {"color": ["red", "green", "purple"]} },
              { "terms": {"make": ["honda", "toyota", "bmw"]} }
            ]
        }
   },
   "aggregations": {
     "all_cars": {
         "global": {},
         "aggs": {
              "colors": {
                "filter" : { "terms": {"make": ["honda", "toyota", "bmw"]} },
                "aggregations": {
                    "filtered_colors": { "terms": {"field": "color.keyword"} }
                }
              },
              "makes": {
                "filter" : { "terms": {"color": ["red", "green"]} },
                "aggregations": {
                    "filtered_makes": { "terms": {"field": "make.keyword"} }
                }
              }
          }
      }
   }
}

我如何知道我可以在哪些字段上进行聚合。有没有办法在运行查询后描述文档的属性?所以我可以知道要聚合的可能字段是什么。

【问题讨论】:

    标签: elasticsearch elasticsearch-5 elasticsearch-aggregation


    【解决方案1】:

    现在我将文章的所有属性存储在一个数组中,我可以像这样快速聚合它们:

    {
      "size": 0,
      "aggregations": {
        "array_aggregation": {
          "terms": {
            "field": "properties.keyword",
            "size": 10
          }
        }
      }
    }
    

    这是朝着正确方向迈出的一步,但这样我不知道属性的类型是什么。

    这是一个示例对象

                "price": 10000,
                "color": "red",
                "make": "honda",
                "sold": "2014-10-28",
                "properties": [
                    "price",
                    "color",
                    "make",
                    "sold"
                ]
    

    【讨论】:

      【解决方案2】:

      您可以使用过滤器聚合来过滤,然后在里面创建一个术语聚合?

      【讨论】:

      • 这将返回一个属性的所有值而不是所有属性
      • 我明白了。我误解了这个案子。可能是你可以使用elastic.co/guide/en/elasticsearch/reference/5.6/… 吗?我的意思是做多个请求。一个用于获取字段,另一个用于计算 aggs……可能很难。
      猜你喜欢
      • 2021-12-12
      • 2012-11-16
      • 2021-08-12
      • 1970-01-01
      • 2021-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多