我搜索过但找不到答案。我正在使用ElasticSearch,但嵌套聚合的聚合计数是错误的。下面是我的映射和我的查询
MAPPING
{
"mappings": {
"providers_courses": {
"properties": {
"course_id": {
"type": "long"
},
"course_name": {
"type": "string"
},
"course_sessions": {
"type": "nested",
"properties": {
"end_date": {
"type": "string"
},
"location": {
"type": "geo_point"
},
"method": {
"type": "string",
"index": "not_analyzed"
},
"places_remaining": {
"type": "long"
},
"price": {
"type": "long"
},
"start_date": {
"type": "string"
},
"total_places": {
"type": "long"
},
"venue_address1": {
"type": "string"
},
"venue_address2": {
"type": "string"
},
"venue_building": {
"type": "string"
},
"venue_city": {
"type": "string"
},
"venue_id": {
"type": "long"
},
"venue_postcode": {
"type": "string"
}
}
},
"disciplines": {
"properties": {
"disciplines": {
"type": "nested",
"include_in_parent": true
},
"id": {
"type": "long"
},
"name": {
"type": "string",
"index": "not_analyzed"
},
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"id": {
"type": "long"
},
"provider_id": {
"type": "long"
},
"provider_name": {
"type": "string"
},
"sectors": {
"properties": {
"id": {
"type": "long"
},
"name": {
"type": "string",
"index": "not_analyzed"
},
"raw": {
"type": "string",
"index": "not_analyzed"
},
"sectors": {
"type": "nested",
"include_in_parent": true
}
}
}
}
}
}
}
QUERY
{
"size":1000,
"query":{
"bool":{
"must":[
{
"match":{
"course_name":"safety"
}
},
{
"nested":{
"path":"course_sessions",
"inner_hits":{
"_source":[
]
},
"query":{
"filtered":{
"query":{
"match_all":[
]
},
"filter":{
"geo_distance":{
"distance":"30miles",
"course_sessions.location":{
"lat":14.3263228,
"lon":-1.8304209
}
}
}
}
}
}
}
]
}
},
"aggs":{
"sectors":{
"filter":{
"match_all":[
]
},
"aggs":{
"sectors":{
"terms":{
"field":"sectors.raw"
}
}
}
},
"disciplines":{
"filter":{
"match_all":[
]
},
"aggs":{
"disciplines":{
"terms":{
"field":"disciplines.raw"
}
}
}
},
"course_type":{
"nested":{
"path":"course_sessions"
},
"aggs":{
"course_type":{
"terms":{
"field":"course_sessions.method"
}
}
}
}
}
}
结果
父元素的计数很好但不适用于嵌套对象 - 我知道最终查询/过滤器需要应用于聚合,但无论我如何尝试它都不起作用。
"aggregations": {
"sectors": {
"doc_count": 10,
"sectors": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "3:Utilities",
"doc_count": 2
},
{
"key": "5:Health, Safety & Environment",
"doc_count": 2
},
{
"key": "6:Supervision, Leadership & Management",
"doc_count": 2
},
{
"key": "2:Offshore & Maritime",
"doc_count": 1
}
]
}
},
"course_type": {
"doc_count": 44,
"course_type": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Classroom",
"doc_count": 44
}
]
}
},
"disciplines": {
"doc_count": 10,
"disciplines": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "3:Instrumentation",
"doc_count": 2
},
{
"key": "6:Production",
"doc_count": 2
},
{
"key": "7:Rigging & Lifting",
"doc_count": 2
},
{
"key": "8:Welding",
"doc_count": 2
},
{
"key": "1:Electrical",
"doc_count": 1
},
{
"key": "2:Engineering",
"doc_count": 1
}
]
}
}
非常感谢任何帮助。