elasticsearch - 使用 Elasticsearch 进行分面导航的最佳方式是什么?
问题描述
我正在尝试使用 Elasticsearch 实现分面导航,并且我遇到了使用带有过滤器的聚合来实现它的方法。
我正在使用的 ES 版本:7.10.2
https://medium.com/swlh/faceted-navigation-for-e-commerce-with-elasticsearch-dbf82bdeb7d4。
问题:在上述文章中提供的方法中,
我们需要为使用除自身之外的所有其他过滤器过滤的每个方面创建一个特定的聚合
例如:我在 4 个方面进行聚合,如颜色、尺寸、品牌和风格,如果我为品牌应用了过滤器:“Prada”和风格:“Evening”,那么查询如下:
{
"query": {
"match": {
"Category": "Dress"
}
},
"aggs": {
"Color": {
"aggs": {
"Color": {
"terms": {
"field": "Color",
"size": 10
}
}
},
"filter": {
"bool": {
"filter": [
{
"terms": {
"Brand": [
"Prada"
]
}
},
{
"terms": {
"Style": [
"Evening"
]
}
}
]
}
}
},
"Size": {
"aggs": {
"Size": {
"terms": {
"field": "Size",
"size": 5
}
}
},
"filter": {
"bool": {
"filter": [
{
"terms": {
"Brand": [
"Prada"
]
}
},
{
"terms": {
"Style": [
"Evening"
]
}
}
]
}
}
},
"Brand": {
"aggs": {
"Brand": {
"terms": {
"field": "Brand",
"size": 10
}
}
},
"filter": {
"bool": {
"filter": [
{
"terms": {
"Style": [
"Evening"
]
}
}
]
}
}
},
"Style": {
"aggs": {
"Style": {
"terms": {
"field": "Style",
"size": 10
}
}
},
"filter": {
"bool": {
"filter": [
{
"terms": {
"Brand": [
"Prada"
]
}
}
]
}
}
}
},
"post_filter": {
"bool": {
"filter": [
{
"terms": {
"Brand": [
"Prada"
]
}
},
{
"terms": {
"Style": [
"Evening"
]
}
}
]
}
}
}
但是在上面的查询中,您可以看到每个聚合都应用了过滤器,这很好,因为我现在只有 2 个过滤器,但是当我有 10 个或更多过滤器时,这个查询会变得非常大,因为每个聚合将应用 10 个过滤器。
有没有办法优化这个?或任何其他比这更好的方法?
任何帮助深表感谢:)
解决方案
推荐阅读
- class - 不是工作代码,但我想问为什么通过类名初始化比对象具有更高的偏好?
- java - 从数据库中检索字符串到 ArrayList,然后使用它来启用 JMenuBar 中的特定项目
- mysql - 在 MySQL 中创建具有更改日期的数据透视表
- javascript - 如何测试返回承诺的函数?
- django - Django2 and Angular2 url integration problem with parameters
- android - 如何获取自定义主题的主题颜色?
- java - Java:优化 while(true) 循环
- c# - 带有 System.Threading.Thread 的 WPF 启动画面
- mongodb - Hadoop with MongoDB storage
- php - Problem with json_decode - Syntax error, malformed JSON