【问题标题】:Elasticsearch null_pointer_exception with top_hits aggregationElasticsearch null_pointer_exception 与 top_hits 聚合
【发布时间】:2019-01-21 21:53:58
【问题描述】:

当子聚合内的嵌套术语聚合内有嵌套的 top_hits 聚合时,我得到一个 null_pointer_exception。我希望得到有效的回复。

重现步骤:

创建映射

PUT http://localhost:9200/test

{
    "mappings": {
        "doc": {
            "properties": {
                "docType": {
                    "type": "text"
                },
                "userId": {
                    "type": "long"
                },
                "userName": {
                    "type": "text"
                },
                "title": {
                    "type": "text"
                },
                "joinField": {
                    "type": "join",
                    "relations": {
                        "post": "comment"
                    }
                }
            }
        }
    }
}

插入示例帖子

PUT http://localhost:9200/test/doc/1
{
    "joinField": {
        "name": "post"
    },
    "docType": "post",
    "title": "Example Post"
}

插入评论

PUT http://localhost:9200/test/doc/2?routing=1

{
    "joinField": {
        "name": "comment",
        "parent": "1"
    },
    "userId": 22,
    "userName": "John Doe",
    "title": "Random comment",
    "docType": "comment"
}

执行搜索

POST http://localhost:9200/test/doc/_search

{
    "aggs": {
        "to-comment": {
            "children": {
                "type": "comment"
            },
            "aggs": {
                "by-user": {
                    "terms": {
                        "field": "userId"
                    },
                    "aggs": {
                        "data": {
                            "top_hits": {
                                "size": 1
                            }
                        }
                    }   
                }
            }
        }
    },
    "query": {
        "bool": {
            "filter": [
                {
                    "term": {
                        "docType": "post"
                    }
                }
            ]
        }
    }
}

回复:

{
    "took": 10,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 4,
        "skipped": 0,
        "failed": 1,
        "failures": [
            {
                "shard": 3,
                "index": "test",
                "node": "0RbF1bIbRO-yN5C1m-HXPA",
                "reason": {
                    "type": "null_pointer_exception",
                    "reason": null
                }
            }
        ]
    },
    "hits": {
        "total": 0,
        "max_score": null,
        "hits": []
    },
    "aggregations": {
        "to-comment": {
            "doc_count": 0,
            "by-user": {
                "doc_count_error_upper_bound": 0,
                "sum_other_doc_count": 0,
                "buckets": []
            }
        }
    }
}

如果我删除查询,它会起作用,但在实际点击中,我只想获取所有帖子。如果我删除术语聚合,它也可以工作,但我想通过其他查询过滤帖子(例如,匹配标题)。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    这似乎是弹性搜索的一个错误。该错误已报告,有望很快得到修复 (https://github.com/elastic/elasticsearch/issues/37650)。

    如果您有任何关于如何构建类似聚合的替代解决方案,请告诉我。

    编辑:您可以使用无痛脚本语言来解决问题:

    "script": {
      "lang": "painless",
      "source": "params._source.userName"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-13
      • 2020-08-30
      • 2019-04-08
      • 2015-12-21
      • 2018-04-11
      • 2017-09-24
      • 2016-06-26
      相关资源
      最近更新 更多