【发布时间】:2016-04-15 16:35:47
【问题描述】:
我有一个非常奇怪的问题/错误,我不明白。我有一个孩子(课程)-父母(大学)的关系。我查询属于某所大学的课程,效果很好。由于我的应用程序的概念,我还需要查询具有属于某个学院的课程的学院,然后汇总结果。我将这个概念用于不同的聚合,除了这个对我没有意义的情况外,一切都很好。请注意:我有两种类型 - 大学和课程 - 类型课程还有一个嵌套对象,称为大学。这是为了能够进行某些聚合,因为 ES 中不支持父聚合。这个概念对我来说非常有效,我认为它与提到的问题/错误没有任何关系。
提前致谢,汉内斯
映射(简化):
types:
college:
mappings:
id: ~
premium: { "type": "boolean" }
boost: { "type": "boolean" }
course:
mappings:
_all: { "analyzer": "text" }
id: { "type": "string", "analyzer": "term" }
name: { "type": "string", "analyzer": "text" }
types: { "type": "string", "analyzer": "term" }
college:
type: "object"
properties:
id: { "type": "string", "analyzer": "term" }
name: { "type": "string", "analyzer": "text" }
_parent:
type: "college"
查询:
GET _search
{
"query": {
"function_score": {
"query": {
"has_child": {
"type": "course",
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"terms": {
"college.id": [
"371"
]
}
}
]
}
}
}
}
}
}
}
},
"aggs": {
"children": {
"children": {
"type": "course"
},
"aggs": {
"filtered": {
"filter": {
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"terms": {
"college.id": [
"371"
]
}
}
]
}
}
}
}
},
"aggs": {
"abschluss": {
"terms": {
"field": "degree",
"size": 0
},
"aggs": {
"unique": {
"cardinality": {
"field": "_parent",
"precision_threshold": 500
}
}
}
},
"coursecount": {
"terms": {
"field": "_parent",
"size": 0
}
}
}
}
}
}
},
"from": 0,
"size": 20
}
结果:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "studiengaenge_dev",
"_type": "college",
"_id": "371",
"_score": 1,
"_source": {
"id": "371",
"premium": true,
"boost": null
}
}
]
},
"aggregations": {
"children": {
"doc_count": 15,
"filtered": {
"doc_count": 0,
"coursecount": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
},
"abschluss": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
}
}
}
【问题讨论】:
-
你运行的是哪个版本的 ES?
-
我正在运行 ES 1.7.2
-
如果我将字段“id”重命名为其他名称“collegeId”,查询将按预期工作。也许名称id在ES中被保留,不能在术语过滤器中使用?我没有回答这个问题,但这对我来说绝对有用..
标签: elasticsearch