记一次elasticsearch查询报错,java.lang.RuntimeException: ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]

elasticsearch查询报错 exception search_phase_execution_exception

工作中遇到了一个特别可笑的事情,一个白痴的菜鸟开发写的查询逻辑触发了一个 elasticsearch查询语法错误,

错误报错是这样的

java.lang.RuntimeException: ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]

查询参数:

{
    "from": 0,
    "size": 10,
    "query": {
        "bool": {
            "must": [
                {
                    "bool": {
                        "must": [
                            {
                                "match_all": {}
                            }, 
                            {
                                "terms": {
                                    "goodsId": [
                                        1,
                                        2,
										......
										//此处省略 大概有 66478 条数据
                                    ], 
                                    "boost": 1
                                }
                            },
                            {
                                "term": {
                                    "goodsType": {
                                        "value": 1
                                    }
                                }
                            }
                        ]
                    }
                }
            ]
        }
    },
    "track_total_hits": 2147483647
}

这个白痴开发居然吧 terms的查询参数里 硬塞了 66478个id进来查询全量数据,真有一种想锤死他的赶脚,terms的最大长度限制是 65535 超过了就会报查询异常,一般脑子没问题的人 不会像上面的查询那样干,如果查询所有有效数据,像下面这样一个简单的查询就可以搞定了

查询所有有效数据

{
    "from": 0,
    "size": 10,
    "query": {
        "bool": {
            "must": [
                {
                    "bool": {
                        "must": [
                            {
                                "term": {
                                    "goodsType": {"value": 1}
                                }
                            }
                        ]
                    }
                }
            ]
        }
    },
    "track_total_hits": 2147483647
}

注意:elasticsearch的terms查询 ,最大长度是 65535,超出之后就会报 查询语法错误,就是上面的报错

本文原创: https://www.catroom.com.cn/article/1424 转载请注明出处。

上一篇 下一篇


推荐文章

评论
说点什么吧?

发表评论

取消回复
  最新文章