фильтр агрегации не работает elasti c поиск - PullRequest
1 голос
/ 01 мая 2020

Я пытаюсь использовать агрегацию фильтров для поддержки множественного выбора значений фасетов из внешнего интерфейса.

У меня есть фильтры цвета и глубины.

Цветовой фильтр содержит значения: черный (5), синий (3), красный (2)

фильтр глубины содержит значения: 70 мм (3), 60 мм (5), 50 мм (3)

Когда я выбираю черный в цветном фильтре все другие варианты (синий, красный) не приходят в ответ.

Я попытался, добавив

"colourAgg": {
        "filter": {
            "match_all": {
                "boost": 1.0
            }
        },
        "aggregations": {
            "colourAgg": {
                "terms": {
                    "field": "colour.keyword",
                    "size": 10,
                    "min_doc_count": 1,
                    "shard_min_doc_count": 0,
                    "show_term_doc_count_error": false,
                    "order": [
                        {
                            "_count": "desc"
                        },
                        {
                            "_key": "asc"
                        }
                    ]
                }
            }
        }
    }

Отображение:

{
"products": {
    "mappings": {
        "properties": {
            "assemblyrequired": {
                "type": "boolean"
            },
            "australianmade": {
                "type": "boolean"
            },
            "australiasellable": {
                "type": "boolean"
            },
            "avgRating": {
                "type": "float"
            },
            "category": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "categorylevel1": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "categorylevel2": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "categorylevel3": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "categoryname": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "colour": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "commercialuse": {
                "type": "boolean"
            },
            "customisable": {
                "type": "boolean"
            },
            "depth": {
                "type": "float"
            },
            "freedelivery": {
                "type": "boolean"
            },
            "height": {
                "type": "float"
            },
            "listprice": {
                "type": "float"
            },
            "materialcode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "moneybackguarantee": {
                "type": "boolean"
            },
            "newrelease": {
                "type": "boolean"
            },
            "numberOfRating": {
                "type": "long"
            },
            "online": {
                "type": "boolean"
            },
            "outdooruse": {
                "type": "boolean"
            },
            "predictivecategorydata": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "pricematchguarantee": {
                "type": "boolean"
            },
            "productid": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "productimageurl": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "productname": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "producttypecode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "promotedprice": {
                "type": "float"
            },
            "sale": {
                "type": "integer"
            },
            "saleprice": {
                "type": "float"
            },
            "sellable": {
                "type": "boolean"
            },
            "sellercode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "shortdescription": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "sku": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "state": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "stylecode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "warrantycode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "weight": {
                "type": "float"
            },
            "width": {
                "type": "float"
            }
        }
    }
}

}

Документ:

{
                "sellercode": "F2OVRX",
                "productid": 13410,
                "saleprice": 4000.2,
                "producttypecode": "Recliner Lounge or Sofa",
                "productimageurl": null,
                "sellable": false,
                "freedelivery": false,
                "promotedprice": null,
                "listprice": 4000.2,
                "productname": "louise chair - cream",
                "outdooruse": null,
                "avgRating": 0.0,
                "warrantycode": null,
                "state": [
                    "SA",
                    "NT"
                ],
                "newrelease": null,
                "sku": "VSTALDBED415_8",
                "height": 66.0,
                "shortdescription": "Stackable light weight chair made from Virgin materials.High strength one piece gas injection moulded technology.160kg weight tested, Catas test certificated",
                "commercialuse": true,
                "customisable": true,
                "weight": null,
                "pricematchguarantee": true,
                "colour": "Black",
                "australianmade": true,
                "depth": 65.0,
                "moneybackguarantee": false,
                "width": 31.0,
                "predictivecategorydata": [
                    "Dressing Table-Dining Table-52"
                ],
                "online": true,
                "materialcode": "Timber",
                "numberOfRating": 0,
                "categoryname": [
                    "Bed - Double",
                    "Dining Table",
                    "Dressing Table",
                    "444",
                    "Bench",
                    null,
                    "M13",
                    "Bed Head"
                ],
                "location": [],
                "assemblyrequired": null,
                "category": [
                    "outdoor",
                    "bed",
                    "doublebeds",
                    "444",
                    "beds",
                    "cat1220",
                    "m13",
                    "cafebarrestaurant"
                ],
                "stylecode": "Safari"
            }

, но все же я получаю только черный цвет. Есть какие-нибудь данные?

Спасибо, Сри.

1 Ответ

1 голос
/ 02 мая 2020

Агрегация обрабатывает документы, возвращаемые частью запроса. Таким образом, если вы выполняете фильтрацию по «черному» в запросе, все документы с черным цветом будут возвращены, и агрегирование будет применено к этим документам.

Вам нужно, чтобы ваше агрегирование применялось ко всем документам в индексе, а не только к ним. возвращается по запросу. Вы можете использовать Глобальное агрегирование для этого

Определяет один пакет всех документов в контексте выполнения поиска. Этот контекст определяется индексами и типами документов, которые вы ищете, но не зависит от самого поискового запроса.

{
  "aggs": {
    "products": {
      "global": {}, --> note
      "aggs": {
        "filtered_docs": {   --> filter certain docs for entire index 
          "filter": {
            "range": {
              "depth": {
                "gte": 60
              }
            }
          },
          "aggs": {
            "colourAgg": {   --> facets for color
              "terms": {
                "field": "colour.keyword",
                "size": 10,
                "min_doc_count": 1,
                "shard_min_doc_count": 0,
                "show_term_doc_count_error": false,
                "order": [
                  {
                    "_count": "desc"
                  },
                  {
                    "_key": "asc"
                  }
                ]
              }
            }
          }
        }
      }
    }
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...