elasticsearch-7 - '在 [field] 下预期 [START_OBJECT],但得到了 [VALUE_STRING] - 范围聚合 - elasticserch 7.9
问题描述
我有一个long
名为 的类型字段notice_period
,其中我的值从15 days
to开始120 days
。我正在寻找一个aggregate
查询来获取所有间隔的频率(count
),即{'to': 15}, {'from': 16, 'to': 30}, {'from': 31, 'to': 45}, {'from': 46, 'to': 60}, {'from': 61, 'to': 90}, {'from': 91}
。
body
for search 查询对我来说如下所示
{
'size': 101,
'query': {
'ids': {
'values': ['id1', 'id2']
}
},
'aggs': {
'notice_period': {
'field': 'notice_period',
'ranges': [
{'to': 15},
{'from': 16, 'to': 30},
{'from': 31, 'to': 45},
{'from': 46, 'to': 60},
{'from': 61, 'to': 90},
{'from': 91}]
}
}
}
因为我正在使用 python,所以我的代码摘录看起来像
from elasticsearch import Elasticsearch
es_client = Elasticsearch('localhost', 9200)
result = es_client.search(index='my_index', body=body_mentioned_above)
但是由于我是 elasticsearch 新手,所以我遇到了错误'parsing_exception', 'Expected [START_OBJECT] under [field], but got a [VALUE_STRING] in [notice_period]'
,有人可以帮我解决这个问题,或者如果我以错误的方式进行操作,任何方向都会非常有帮助。提前致谢。
解决方案
我发现了我正在做的错误,我在范围级别又错过了一个键
所以基本上它适用于
{
'size': 101,
'query': {
'ids': {
'values': ['id1', 'id2']
}
},
'aggs': {
'notice_period': {
'range': {
'field': 'notice_period',
'ranges': [
{'to': 15},
{'from': 16, 'to': 30},
{'from': 31, 'to': 45},
{'from': 46, 'to': 60},
{'from': 61, 'to': 90},
{'from': 91}]
}}
}
}
推荐阅读
- python - Django ModuleNotFoundError:没有名为“EmailIngestionDemo.EmailIngestionDemo”的模块
- java - 使用 <> 时 JDBI 查询失败
- java - 嗨,你知道如何在 Android Studio 的应用屏幕上显示一个对象而不是其他对象吗?(爪哇)
- flutter - 如何将 get_it 用于 Provider.of
(语境)? - react-native - 如何在抽屉导航中制作动画
- typescript - Vue 3 PropType 看不到界面
- gradle - gradle:如何删除任务依赖
- javascript - 如何将双精度数组转换为 JS 数组?
- python - 如何格式化 django timezone.now()
- python - 如何将可能的类名传递给 distilbert