0
我一直在尝试很长一段时间,但看不到问题。如果有更多ES经验的人能够向我提出正确的方向,我会很高兴。我有一个父母类型(学院)和一个孩子类型(课程)。课程有3级嵌套聚合(Subjectgroup)。现在我试图说明有多少大学在大学查询中提供具有单个学科组的课程。嵌套的子集合返回“错误”父集doc_count
这里是我的映射:
indexes:
studiengaenge:
index_name: studiengaenge_dev
settings:
index:
analysis:
analyzer:
lc_term:
type: custom
tokenizer: keyword
filter: lowercase
types:
college:
mappings:
id: ~
course:
mappings:
id: ~
name: ~
subjectgroups:
type: "nested"
properties:
name: { "type": "string", "index": "analyzed", "analyzer": "lc_term" }
area:
type: "nested"
properties:
name: { "type": "string", "index": "analyzed", "analyzer": "lc_term" }
field:
type: "nested"
properties:
name: { "type": "string", "index": "analyzed", "analyzer": "lc_term" }
_parent:
type: "college"
查询:
GET college/_search?search_type=count
{
"query": {
"has_child": {
"type": "course",
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"nested": {
"path": "subjectgroups",
"filter": {
"terms": {
"subjectgroups.name": [
"lehramt"
]
}
}
}
}
]
}
}
}
}
}
},
"aggs": {
"children": {
"children": {
"type": "course"
},
"aggs": {
"fachgruppen": {
"nested": {
"path": "course.subjectgroups"
},
"aggs": {
"filtered": {
"filter": {
"terms": {
"subjectgroups.name": [
"lehramt"
]
}
},
"aggs": {
"fachgruppe": {
"terms": {
"field": "subjectgroups.name"
},
"aggs": {
"reverse_nested": {
"reverse_nested": {},
"aggs": {
"doc_count_college": {
"cardinality": {
"field": "_parent"
}
}
}
},
"studienbereich": {
"nested": {
"path": "course.subjectgroups.area"
},
"aggs": {
"studienbereich": {
"terms": {
"field": "subjectgroups.area.name"
},
"aggs": {
"reverse_nested": {
"reverse_nested": {},
"aggs": {
"doc_count_college": {
"cardinality": {
"field": "_parent"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
结果:
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 123,
"max_score": 0,
"hits": []
},
"aggregations": {
"children": {
"doc_count": 12289,
"fachgruppen": {
"doc_count": 15029,
"filtered": {
"doc_count": 4582,
"fachgruppe": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "lehramt",
"doc_count": 4582,
"reverse_nested": {
"doc_count": 3786,
"doc_count_college": {
"value": 124
}
},
"studienbereich": {
"doc_count": 4582,
"studienbereich": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "schulische fächer",
"doc_count": 3938,
"reverse_nested": {
"doc_count": 3399,
"doc_count_college": {
"value": 130
}
}
},
{
"key": "berufliche fachrichtungen",
"doc_count": 357,
"reverse_nested": {
"doc_count": 315,
"doc_count_college": {
"value": 105
}
}
},
{
"key": "sonderpädagogik, inklusive pädagogik",
"doc_count": 287,
"reverse_nested": {
"doc_count": 287,
"doc_count_college": {
"value": 32
}
}
}
]
}
}
}
]
}
}
}
}
}
}
的问题是,即使有只有123结果(学院),第2级subjectgroup的聚集告诉我,有130所院校“钥匙”:“schulischefächer”。 任何帮助,不胜感激。谢谢,汉斯
感谢您的快速响应。我将设置更改为仅使用一个分片,但不幸的是,它对结果没有任何影响。我读到ES在这些计算上不是100%正确的,但这看起来很不正确。我认为肯定还有其他问题。如果将所有文件都纳入计算并且不应用过滤器/查询,那么130将是正确的金额。这可能与它有什么关系? – HKandulla
我编辑了问题(结果)到已更改的设置(一个分片)。 – HKandulla
你说得对。这只是ES的准确性问题,而不是查询。我添加了一个500的“precision_threshold”,我现在得到了确切的数字。谢谢! – HKandulla