【发布时间】:2023-03-18 03:04:01
【问题描述】:
不知何故,我似乎无法获得包含我的聚合的响应...
使用 curl 可以按预期工作:
HBZUMB01$ curl -XPOST "http://localhost:9200/contents/_search" -d '{
"size": 0,
"aggs": {
"sport_count": {
"value_count": {
"field": "dwid"
}
}
}
}'
我得到了回应:
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 90,
"max_score": 0.0,
"hits": []
},
"aggregations": {
"sport_count": {
"value": 399
}
}
}
但是使用 rails 中的代码:
query = '{
"size": 0,
"aggs": {
"sport_count": {
"value_count": {
"field": "dwid"
}
}
}
}'
@response = Content.search(query).to_json
在浏览器中渲染
respond_to do |format|
format.html do
render text: "#{@response}"
end
我得到一个空响应:
[ ]
如何在此处打印我使用 curl 获得的聚合?
【问题讨论】:
-
您用于集成 Elasticsearch 的 gem 是什么?
标签: ruby ruby-on-rails-4 elasticsearch