elasticsearch - 布尔查询格式错误
问题描述
错误消息: “[bool] 格式错误的查询,应为 [END_OBJECT] 但找到 [FIELD_NAME]”)
询问:
{'query':{
'bool': {
'must': {
'bool': {
'should': [
{'match': {'title' : a[0]}},
{'match': {'title' : a[1]}}
],
'minimum_should_match': 1
}
}
}
},
}
我已经搜索了几个问题,但仍然无法弄清楚查询中的错误位置。
更新:这完全是我的问题。我认为错误出在布尔查询上,所以我删除了一些我认为与原始问题无关的代码。实际查询是这样的:
search_body_try1 = {'query':{
'bool': {
'must': {
'bool': {
'should': [
{'match': {'title' : a[0]}},
{'match': {'title' : a[1]}}
],
'minimum_should_match': 1
}
}
},
'sort':[{'_score': {'order':'desc'}},
{'_id': {'order':'desc'}}]
},
'size':200
}
现在在我看来问题是'sort'
应该放在外面query
?
解决方案
查询确实格式不正确。sort
需要与和处于同一水平size
-query
即类似于以下内容:
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"match": {
"title": a[0]
}
},
{
"match": {
"title": a[1]
}
}
],
"minimum_should_match": 1
}
}
]
}
},
"sort": [
{
"_score": {
"order": "desc"
}
},
{
"_id": {
"order": "desc"
}
}
],
"size": 200
}
如果您有score
字段,请替换_score
为score
. 与_id
.
推荐阅读
- tensorflow - 在 Tensorflow 对象检测 API 中绘制验证损失
- python - Python-在文本文件中加入列表项
- android - Android:录制视频 30 秒,30 秒后仅录制音频
- git - GitHub:合并后提交更改
- linear-programming - CPLEX、Gurobi 和 FICO Xpress 之间的性能差异的解释使用内点法(障碍)没有交叉?
- testing - 如何在 Jmeter 中获取字符串长度并减去用户定义的变量
- unity3d - 当我在 android mobile 上构建时,我的健康点未设置为正确的值
- java - 异常选择签名:无法验证签名
- python - 如何在python中仅给具有默认值的函数的第二个参数赋值
- css - 如何在 Bootstrap Select2 Dropdown 中为边框颜色应用 CSS