Facets 绝对是亚马逊类别搜索风格的最佳选择。为了在尽可能少的查询中检索所有方面,您可以很容易地做到这一点,只需包含更多。我使用了 Sense chrome 扩展,因为它非常漂亮且易于用于搜索示例。对于这个例子,我放置了一些带有名称、价格、制造商、类别、颜色的产品文档。如您所见,我们已经在 match all 中搜索了所有这些方面。你可以做你喜欢的查询,甚至做全局方面,或任意数量的方面(范围、直方图等)。这实际上完全取决于您想要什么文件,以及数据是如何形成的。其中一个非常令人兴奋的部分是下一件大事Aggregations!您可以使用聚合进行出色的搜索。假设您有一个时间戳和一个位置,您可以对特定位置的时间之间的颜色进行聚合。 qbox.io 将发布一篇博文,介绍未来几天您可以使用 aggs 做的一些有趣的事情。
DELETE /test_index
PUT /test_index
PUT /test_index/product/1
{
"name":"prod1",
"price":19.95,
"manufacturer":"manu1",
"category":["cat1","cat2"],
"color":"red"
}
PUT /test_index/product/2
{
"name":"prod2",
"price":25,
"manufacturer":"manu2",
"category":["cat2","cat3"],
"color":"yellow"
}
PUT /test_index/product/3
{
"name":"prod3",
"price":4.99,
"manufacturer":"manu2",
"category":["cat1","cat2","cat3"],
"color":"yellow"
}
PUT /test_index/product/4
{
"name":"prod4",
"price":19.95,
"manufacturer":"manu3",
"category":["cat1","cat3"],
"color":"blue"
}
POST /test_index/_search
{
"query": {
"match_all": {}
},
"facets" : {
"price_stats" : {
"statistical" : {
"field" : "price"
}
},
"color_terms" : {
"terms": {
"field": "color",
"size": 10
}
},
"manufacturer_terms" : {
"terms": {
"field": "manufacturer",
"size": 10
}
},
"category_terms" : {
"terms": {
"field": "category",
"size": 10
}
}
}
}`