0

我已经看到了一些关于Elastic的分面搜索的例子,但是他们都事先知道你想要创建的分区的字段。在Eshop的网店中进行分面搜索

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

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

我有这个疑问现在:

{ 
    "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"} } 
       } 
       } 
      } 
     } 
    } 
} 

我怎样才能知道哪些领域我可以聚合。有没有办法在运行查询后描述文档的属性?所以我可以知道可能的领域,汇总,是。

回答

0

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

+0

这将返回属性的所有值,而不是所有的属性 – brechtvhb

+0

我看到的。我误解了这个案子。可能是你可以使用https://www.elastic.co/guide/en/elasticsearch/reference/5.6/mapping-field-names-field.html?我的意思是做多个请求。一个得到领域,另一个来计算aggs ...可能很难。 – dadoonet

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" 
      ]