在ElasticSearch上运行无痛脚本时出现BadRequestError

raogr8fs  于 2023-03-01  发布在  ElasticSearch
关注(0)|答案(1)|浏览(229)

我是elasticsearch的新手,我尝试根据事件类型列出最长的打开事件,给出以下Map

mappings = {
        "properties": {
            "type": {"type": "keyword"},
            "id": {"type": "integer"},
            "state": {"type": "keyword"},
            "title": {"type": "text"},
            "body": {"type": "text"},
            "user": {"type": "keyword"},
            "event_start_date": {"type": "date"},
            "event_end_date": {"type": "date"},
            "repository": {"type": "text"},
            "repository_owner": {"type": "text"},
            "tags": {"type": "text"}
    }
}

我尝试执行以下操作以获取end_date和start_date之间的差异

"query": {
        "bool": {
            "must": [
                {
                    "script": {
                        "script": "(doc['event_end_date'].date.millis - doc['event_start_date'].date.millis)/1000/86400 < 365"
                    }
                }
            ]
        }
    }

当我尝试使用pythonelasticsearch客户端运行我的搜索查询时,我得到了以下错误
BadRequestError: BadRequestError(400, 'search_phase_execution_exception', 'runtime error')
这只是查询的内部部分,我得到了这个错误,我也需要关于聚合的帮助。
谢谢

bsxbgnwa

bsxbgnwa1#

尝试将doc['event_end_date'].date.millis替换为doc['event_end_date'].value.millis,并对doc['event_start_date'].value.millis执行相同操作。
无论如何,我强烈建议您通过在接收时进行计算并将结果存储在专用字段(例如duration)中来替换这种查询,以便稍后在查询时检查。

相关问题