这是我使用邮递员localhost:9201/response_v2_862875ee3a88a6d09c95bdbda029ce2b/_search
此端点的请求正文
{
"_source": ["_id"],
"from": 1,
"size": 10,
: {
"should": {
"match": {
}
}, {
"range": {
"_updated_at": {
"from": "36163",
"include_lower": true,
"include_upper": true,
"to": null
}
}
}]
}
}
}
到这个网址本地主机:9201/rensedbda029ce2b/_search
我得到的结果 https://gist.gith
但是当我从服务器向 ES 发出相同的请求时,我收到一条错误消息,指出"弹性:错误 400(错误请求):预期 [START_OBJECT] 但找到 [START_ARRAY] [type=parsing_exception]">
这些是我的代码的一些片段。我从另一个 util 函数获取查询,并在调用 ES 时使用它。
这是对 ESres, err = r.esConn.Search(indexName).e(requestBody.ResponsePageLength).Do(ctx)
的调用
查询生成器函数是这样的,它将从请求正文中提取的参数带到我的服务器,并基于此构建查询。
func CreateMonitoringPipeline(maxResponseTime string, responseQueries []ResponseQuery, baselineFormId string) *elastic.BoolQuery {
finalQuery := elastic.NewBoolQuery()
dateRangeMatchQuery := elastic.NewRangeQuery("_updated_at").
Gte(maxResponseTime)
finalQuery.Filter(dateRangeMatchQuery)
}
return finalQuery
}
我不知道为什么会这样?我的 ES 使用 ES 二进制文件运行,我的服务器在 docker 容器中运行。
对ES和golang来说是全新的,所以请帮忙。
更新:
这是我使用SetTraceLog
记录请求时得到的
| ELASTICPOST /resp8ecf8427e/_search HTTP/1.1
| Host: 172.17.0.1:9201
| User-Agent: elastic/5.0.81 (linux-amd64)
| Transfer-Encoding: chunked
| Accept: application/json
| Content-Type: application/json
| Accept-Encoding: gzip
|
| 7
| ["_id"]
| 0
我不明白7和["_id"]
是什么意思。这是 ES 收到的请求正文吗?
感谢您上传日志,您是对的,["_id"]
是正在发送的请求。问题出在请求行中,因为Source([]string{"_id"})
没有按预期将源字段设置为["_id"]
,而是:
Source 允许用户手动设置请求正文,而无需使用 Elastic 中的任何结构和接口。
https://godoc.org/github.com/olivere/elastic#SearchService.Source
您想改用FetchSourceContext
:
res, err = r.esConn.Search(indexName).From(requestBody.MaxResponseTimestampCount).FetchSourceContext(elastic.NewFetchSourceContect(true). Include("_id")).Query(query).Size(requestBody.ResponsePageLength).Do(ctx)
https://godoc.org/github.com/olivere/elastic#SearchService.FetchSourceContext