- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经花了整整一周的时间来解决这个问题,但没有希望解决它。我正在关注这个(很老)article on e-commerce search and faceted filtering等,到目前为止它运行良好(搜索结果很好,当在查询中应用过滤器时聚合效果很好。我使用的是 ElasticSearch 6.1.1。
但是因为我想让我的用户在构面上执行多项选择,所以我将过滤器移到了 post_filter 部分。此 仍然运行良好 ,它会正确过滤结果并准确显示整个文档集的聚合计数。
阅读后this question on StackOverflow ,我意识到我必须使用“过滤”聚合和“特殊”聚合来执行一些疯狂的杂技,以相互修剪聚合以显示正确的计数并允许同时使用多个过滤器。我已经要求对该问题进行一些澄清,但尚未得到答复(这是一个老问题)。
我一直在努力解决的问题是在 上获得一组过滤聚合。嵌套字段 其中所有方面都用所有过滤器过滤。
我的计划是使用一般聚合(未过滤)并保持选定的方面聚合未过滤(以便我可以选择多个条目)但使用当前选择的方面过滤所有其他聚合,以便我只能显示我仍然可以的过滤器申请。
但是,如果我在文档上使用相同的过滤器(工作正常),并将过滤器放入过滤后的聚合中,它们将无法按预期工作。计数全错了。我知道聚合是在过滤器之前计算的,这就是我在我想要的聚合上复制过滤器的原因。
这是我的查询:
"query": {
"bool": {
"must": [
{
"multi_match": {
"fields": [
"search_data.full_text_boosted^7",
"search_data.full_text^2"
],
"type": "cross_fields",
"analyzer": "full_text_search_analyzer",
"query": "some book"
}
}
]
}
}
"post_filter" : {
"bool" : {
"must" : [
{
"nested": {
"path": "string_facets",
"query": {
"bool" : {
"filter" :
[
{ "term" : { "string_facets.facet_name" : "Cover colour" } },
{ "terms" : { "string_facets.facet_value" : [ "Green" ] } }
]
}
}
}
}
]
}
}
"agg_string_facets": {
"nested": {
"path": "string_facets"
},
"aggregations": {
"facet_name": {
"terms": {
"field": "string_facets.facet_name"
},
"aggregations": {
"facet_value": {
"terms": {
"field": "string_facets.facet_value"
}
}
}
}
}
}
"agg_all_facets_filtered" : {
"filter" : {
"bool" : {
"must" : [
{
"nested": {
"path": "string_facets",
"query": {
"bool" : {
"filter" : [
{ "term" : { "string_facets.facet_name" : "Cover colour" } },
{ "terms" : { "string_facets.facet_value" : [ "Green" ] } }
]
}
}
}
}]
}
},
"aggs" : {
"agg_all_facets_filtered" : {
"nested": { "path": "string_facets" },
"aggregations": {
"facet_name": {
"terms": { "field": "string_facets.facet_name" },
"aggregations": {
"facet_value": {
"terms": { "field": "string_facets.facet_value" }
}
}
}
}
}
}
{
"key": "Cover colour",
"doc_count": 4,
"facet_value": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Green",
"doc_count": 4
}
]
}
}
{
"size" : 0,
"query": {
"bool": {
"must": [
{
"multi_match": {
"fields": [
"search_data.full_text_boosted^7",
"search_data.full_text^2"
],
"type": "cross_fields",
"analyzer": "full_text_search_analyzer",
"query": "bible"
}
}
]
}
},
"post_filter" : {
"bool" : {
"must" : [
{
"nested": {
"path": "string_facets",
"query": {
"bool" : {
"filter" :
[
{ "term" : { "string_facets.facet_name" : "Cover colour" } },
{ "terms" : { "string_facets.facet_value" : [ "Green" ] } }
]
}
}
}
}
]
}
},
"aggregations": {
"agg_string_facets": {
"nested": {
"path": "string_facets"
},
"aggregations": {
"facet_name": {
"terms": {
"field": "string_facets.facet_name"
},
"aggregations": {
"facet_value": {
"terms": {
"field": "string_facets.facet_value"
}
}
}
}
}
},
"agg_all_facets_filtered" : {
"filter" : {
"bool" : {
"must" : [
{
"nested": {
"path": "string_facets",
"query": {
"bool" : {
"filter" : [
{ "term" : { "string_facets.facet_name" : "Cover colour" } },
{ "terms" : { "string_facets.facet_value" : [ "Green" ] } }
]
}
}
}
}]
}
},
"aggs" : {
"agg_all_facets_filtered" : {
"nested": { "path": "string_facets" },
"aggregations": {
"facet_name": {
"terms": { "field": "string_facets.facet_name" },
"aggregations": {
"facet_value": {
"terms": { "field": "string_facets.facet_value" }
}
}
}
}
}
}
}
}
}
{
"key": "Cover colour",
"doc_count": 483,
"facet_value": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 111,
"buckets": [
{
"key": "Black",
"doc_count": 87
},
{
"key": "Brown",
"doc_count": 75
},
{
"key": "Blue",
"doc_count": 45
},
{
"key": "Burgundy",
"doc_count": 43
},
{
"key": "Pink",
"doc_count": 30
},
{
"key": "Teal",
"doc_count": 27
},
{
"key": "Tan",
"doc_count": 20
},
{
"key": "White",
"doc_count": 18
},
{
"key": "Chocolate",
"doc_count": 14
},
{
"key": "Green",
"doc_count": 13
}
]
}
}
{
"key": "Cover colour",
"doc_count": 4,
"facet_value": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Green",
"doc_count": 4
}
]
}
}
"hits": {
"total": 13,
"max_score": 17.478987,
"hits": [
{
"_index": "redacted",
"_type": "product",
"_id": "33107",
"_score": 17.478987,
"_source": {
"type": "product",
"document_id": 33107,
"search_data": {
"full_text": "hcsb compact ultrathin bible mint green leathertouch holman bible staff leather binding 9781433617751 ",
"full_text_boosted": "HCSB Compact Ultrathin Bible Mint Green Leathertouch Holman Bible Staff "
},
"search_result_data": {
"name": "HCSB Compact Ultrathin Bible, Mint Green Leathertouch (Leather)",
"preview_image": "/images/products/medium/0.jpg",
"url": "/Products/ViewOne.aspx?ProductId=33107"
},
"string_facets": [
{
"facet_name": "Binding",
"facet_value": "Leather"
},
{
"facet_name": "Bible size",
"facet_value": "Compact"
},
{
"facet_name": "Bible size",
"facet_value": "Ultrathin"
},
{
"facet_name": "Bible version",
"facet_value": "HCSB"
},
{
"facet_name": "Cover colour",
"facet_value": "Green"
}
]
}
},
{
"_index": "redacted",
"_type": "product",
"_id": "17240",
"_score": 17.416323,
"_source": {
"type": "product",
"document_id": 17240,
"search_data": {
"full_text": "kjv thinline bible compact leather binding 9780310439189 ",
"full_text_boosted": "KJV Thinline Bible Compact "
},
"search_result_data": {
"name": "KJV Thinline Bible, Compact (Leather)",
"preview_image": "/images/products/medium/17240.jpg",
"url": "/Products/ViewOne.aspx?ProductId=17240"
},
"string_facets": [
{
"facet_name": "Binding",
"facet_value": "Leather"
},
{
"facet_name": "Bible size",
"facet_value": "Compact"
},
{
"facet_name": "Bible size",
"facet_value": "Thinline"
},
{
"facet_name": "Bible version",
"facet_value": "KJV"
},
{
"facet_name": "Cover colour",
"facet_value": "Green"
}
]
}
},
{
"_index": "redacted",
"_type": "product",
"_id": "17243",
"_score": 17.416323,
"_source": {
"type": "product",
"document_id": 17243,
"search_data": {
"full_text": "kjv busy mom's bible leather binding 9780310439134 ",
"full_text_boosted": "KJV Busy Mom'S Bible "
},
"search_result_data": {
"name": "KJV Busy Mom's Bible (Leather)",
"preview_image": "/images/products/medium/17243.jpg",
"url": "/Products/ViewOne.aspx?ProductId=17243"
},
"string_facets": [
{
"facet_name": "Binding",
"facet_value": "Leather"
},
{
"facet_name": "Bible size",
"facet_value": "Pocket"
},
{
"facet_name": "Bible size",
"facet_value": "Thinline"
},
{
"facet_name": "Bible version",
"facet_value": "KJV"
},
{
"facet_name": "Cover colour",
"facet_value": "Pink"
},
{
"facet_name": "Cover colour",
"facet_value": "Green"
}
]
}
},
{
"_index": "redacted",
"_type": "product",
"_id": "33030",
"_score": 15.674053,
"_source": {
"type": "product",
"document_id": 33030,
"search_data": {
"full_text": "apologetics study bible for students grass green leathertou mcdowell sean; holman bible s leather binding 9781433617720 ",
"full_text_boosted": "Apologetics Study Bible For Students Grass Green Leathertou Mcdowell Sean; Holman Bible S"
},
"search_result_data": {
"name": "Apologetics Study Bible For Students, Grass Green Leathertou (Leather)",
"preview_image": "/images/products/medium/33030.jpg",
"url": "/Products/ViewOne.aspx?ProductId=33030"
},
"string_facets": [
{
"facet_name": "Binding",
"facet_value": "Leather"
},
{
"facet_name": "Bible designation",
"facet_value": "Study Bible"
},
{
"facet_name": "Bible designation",
"facet_value": "Students"
},
{
"facet_name": "Bible feature",
"facet_value": "Indexed"
},
{
"facet_name": "Cover colour",
"facet_value": "Green"
}
]
}
},
{
"_index": "redacted",
"_type": "product",
"_id": "33497",
"_score": 15.674053,
"_source": {
"type": "product",
"document_id": 33497,
"search_data": {
"full_text": "hcsb life essentials study bible brown / green getz gene a.; holman bible st imitation leather 9781586400446 ",
"full_text_boosted": "HCSB Life Essentials Study Bible Brown Green Getz Gene A ; Holman Bible St"
},
"search_result_data": {
"name": "HCSB Life Essentials Study Bible Brown / Green (Imitation Leather)",
"preview_image": "/images/products/medium/33497.jpg",
"url": "/Products/ViewOne.aspx?ProductId=33497"
},
"string_facets": [
{
"facet_name": "Binding",
"facet_value": "Imitation Leather"
},
{
"facet_name": "Bible designation",
"facet_value": "Study Bible"
},
{
"facet_name": "Bible version",
"facet_value": "HCSB"
},
{
"facet_name": "Binding",
"facet_value": "Imitation leather"
},
{
"facet_name": "Cover colour",
"facet_value": "Brown"
},
{
"facet_name": "Cover colour",
"facet_value": "Green"
}
]
}
}
}
最佳答案
谜团已揭开!感谢您的输入,事实证明我使用的版本(6.1.1)有一个错误。我不知道错误到底是什么,但我已经安装了 ElasticSearch 6.5,重新索引了我的数据并且没有更改查询或映射,一切正常!
现在,我不知道我是否应该向 ES 提交错误报告,或者只是留下它,因为它是一个较旧的版本并且他们已经继续前进。
关于ElasticSearch post_filter 和过滤聚合的行为不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53888524/
我有一个 Cassandra 集群,里面有 4 个表和数据。 我想使用聚合函数(sum,max ...)发出请求,但我在这里读到这是不可能的: http://www.datastax.com/docu
我有以下两张表 Table: items ID | TITLE 249 | One 250 | Two 251 | Three 我投票给这些: Table: votes VID | IID | u
这个问题在这里已经有了答案: Update MongoDB field using value of another field (12 个答案) 关闭 3 年前。 我想根据另一个“源”集合的文档中
我的收藏包含以下文件。我想使用聚合来计算里面有多少客户,但我遇到了一些问题。我可以获得总行数,但不能获得总(唯一)客户。 [{ _id: "n001", channel: "Kalip
我有下表 Id Letter 1001 A 1001 H 1001 H 1001 H 1001 B 1001 H 1001 H 1001
得到一列的表 ABC。 “创建”的日期列。所以样本值就像; created 2009-06-18 13:56:00 2009-06-18 12:56:00 2009-06-17 14:02:0
我有一个带有数组字段的集合: {[ name:String buyPrice:Int sellPrice:Int ]} 我试图找到最低和最高买入/卖出价格。在某些条目中,买入或卖出价格为零
我有以下问题: 在我的 mongo db 中,我有以下结构: { "instanceId": "12", "eventId": "0-1b", "activityType":
下面给出的是我要在其上触发聚合查询的 Elasticsearch 文档。 { "id": 1, "attributes": [ { "fieldId": 1,
我正在使用 Django 的 aggregate query expression总计一些值。最终值是一个除法表达式,有时可能以零作为分母。如果是这种情况,我需要一种方法来逃避,以便它只返回 0。 我
我正在学习核心数据,特别是聚合。 当前我想要做的事情:计算表中在某些条件上具有逆关系的多对关系的记录数。 目前我正在这样做: NSExpression *ex = [NSExpression expr
我需要有关 Delphi 中的 ClientDatasets 的一些帮助。 我想要实现的是一个显示客户的网格,其中一列显示每个客户的订单数量。我将 ClientDataset 放在表单上并从 Delp
我的集合有 10M 个文档,并且有一个名为 movieId 的字段;该文档具有以下结构: { "_id" : ObjectId("589bed43e3d78e89bfd9b779"), "us
这个问题已经有答案了: What is the difference between association, aggregation and composition? (21 个回答) 已关闭 9
我在 elasticsearch 中有一些类似于这些示例的文档: { "id": ">", "list": [ "a", "b", "c" ] } { "id"
我正在做一些聚合。但是结果完全不是我所期望的,似乎它们没有聚合索引中与我的查询匹配的所有文档,在这种情况下 - 它有什么好处? 例如,首先我做这个查询: {"index":"datalayer","t
假设我在 ES 中有这些数据。 | KEY | value | |:-----------|------------:| | A |
可能在我的文档中,我有一个被分析的文本字段。我只是在ElasticSearch AggregationAPI中迷路了。我需要2种不同情况的支持: 情况A)结果是带有计数标记(条款)的篮子下降。 情况B
我正在为网上商店构建多面过滤功能,如下所示: Filter on Brand: [ ] LG (10) [ ] Apple (5) [ ] HTC (3) Filter on OS: [ ] Andr
我有一个父/子关系并且正在搜索 child 。 是否可以在父属性上创建聚合? 例如parent 是 POST,children 是 COMMENT。如果父项具有“类别”属性,是否可以搜索 COMMEN
我是一名优秀的程序员,十分优秀!