【发布时间】:2020-12-08 00:09:28
【问题描述】:
我正在尝试对我知道运行正常的本地 Elasticsearch 实例运行以下查询,但是由于查询显然格式错误,我收到 400 错误:
{
"size": 10,
"from": 0,
"query": {
"bool": {
"filter": null,
"must": [
{
"bool": null,
"match": null,
"match_phrase": null,
"query_string": {
"default_field": "name",
"query": "Test Name"
},
"range": null
}
],
"must_not": null,
"should": null
},
"match": null,
"match_phrase": null,
"query_string": null,
"range": null
}
}
注意:有一堆空值参数,因为查询是根据自定义 OpenAPI 规范自动生成的 - 这些是 Elasticsearch 应该忽略的参数,我是 不试图通过任何空值字段查找或过滤。以这种方式使用空值参数是否存在问题?
具体报错信息如下:
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[bool] query malformed, no start_object after query name",
"line": 1,
"col":67
}
],
"type": "x_content_parse_exception",
"reason": "[1:67] [bool] failed to parse field [must]",
"caused_by": {
"type": "parsing_exception",
"reason": "[bool] query malformed, no start_object after query name",
"line": 1,
"col": 67
}
},
"status":400
}
注意:错误中列出的行号和列号将不准确,因为我已格式化查询以提高可读性,原始查询除了查询字符串中没有空格。
我已经阅读了官方的 Elasticsearch API 文档,试图找出我做错了什么,并在网上发现一些人有类似的解析错误,他们的错误是无关的,而且他们显然没有具体的问题空值搜索参数,所以我很难弄清楚这里出了什么问题。在没有空值参数的情况下运行相同的查询似乎可行,所以也许我认为它们通常不应该成为 Elasticsearch 解析/忽略的问题?话虽如此,错误消息表明未能解析 bool 查询中的“必须”这一事实表明 "filter": null 行已正确解析,因此空值应该没问题...
【问题讨论】:
标签: elasticsearch elasticsearch-dsl