我有一个原因”:“ [查询]查询格式错误,查询名称后没有start_object”错误,不确定原因。
该查询旨在获取两个日期字段之间的差异并计算所有结果的平均值,我相信这应该可以,但可能不起作用。
任何帮助将不胜感激。
我使用的是弹性版本5.6.12
以下查询:
POST index_my.test/_search
{
"size":10,
"query": {
"bool": {
"must": [
{
"query":
"match_all": {}
}
}
]
}
"filter": {
"and": [
{
"exists": {
"field": "activity.timeline.found"
}
}
{
"exists": {
"field": "activity.timeline.sent"
}
}
]
},
"aggs": {
"avg_timedifference": {
"avg": {
"script" : "Math.ceil(doc['activity.timeline.found'].value - doc['activity.timeline.sent'].value)"
}
}
}
}
答案 0 :(得分:1)
您忘记了“过滤器”之前的逗号。试试这个:
POST index_my.test/_search
{
"size":10,
"query": {
"bool": {
"must": [
{
"query":
"match_all": {}
}
}
]
},
"filter": {
"and": [
{
"exists": {
"field": "activity.timeline.found"
}
}
{
"exists": {
"field": "activity.timeline.sent"
}
}
]
},
"aggs": {
"avg_timedifference": {
"avg": {
"script" : "Math.ceil(doc['activity.timeline.found'].value - doc['activity.timeline.sent'].value)"
}
}
}
}