弹性搜索返回对象与总和
我试图通过通过弹性搜索产生的收入来获取前100位客人的清单。为此,我使用术语
和sum
congregation。但是,它确实返回正确的值,我想用聚合返回整个guest
对象。
这是我的查询:
GET reservations/_search
{
"size": 0,
"aggs": {
"top_revenue": {
"terms": {
"field": "total",
"size": 100,
"order": {
"top_revenue_hits": "desc"
}
},
"aggs": {
"top_revenue_sum": {
"sum": {
"field": "total"
}
}
}
}
}
}
这返回了前100位客人的列表,但只有他们所花费的数量:
{
"aggregations" : {
"top_revenue" : {
"doc_count_error_upper_bound" : -1,
"sum_other_doc_count" : 498,
"buckets" : [
{
"key" : 934.9500122070312,
"doc_count" : 8,
"top_revenue_hits" : {
"value" : 7479.60009765625
}
},
{
"key" : 922.0,
"doc_count" : 6,
"top_revenue_hits" : {
"value" : 5532.0
}
},
...
]
}
}
}
我如何获取查询以返回整个guests
对象,而不仅仅是总和金额。
当我运行获取Reservations/_search
时,它会返回:
{
"hits": [
{
"_index": "reservations",
"_id": "1334620",
"_score": 1.0,
"_source": {
"id": "1334620",
"total": 110.8,
"payment": "unpaid",
"contact": {
"name": "John Doe",
"email": "[email protected]"
}
}
},
... other reservations
]
}
我想让它返回使用sum
gentregation。
我尝试使用top_hits
汇总,使用_Source
它确实返回了整个guest> Guest
对象,但并未显示所花费的总金额。并且在将_source
添加到sum
聚合时会出现错误。
我可以用sum
聚合返回整个guest
对象,还是这不是正确的方法?
I am trying to get a list of the top 100 guests by revenue generated with Elastic Search. To do this I am using a terms
and a sum
aggregation. However it does return the correct values, I wan to return the entire guest
object with the aggregation.
This is my query:
GET reservations/_search
{
"size": 0,
"aggs": {
"top_revenue": {
"terms": {
"field": "total",
"size": 100,
"order": {
"top_revenue_hits": "desc"
}
},
"aggs": {
"top_revenue_sum": {
"sum": {
"field": "total"
}
}
}
}
}
}
This returns a list of the top 100 guests but only the amount they spent:
{
"aggregations" : {
"top_revenue" : {
"doc_count_error_upper_bound" : -1,
"sum_other_doc_count" : 498,
"buckets" : [
{
"key" : 934.9500122070312,
"doc_count" : 8,
"top_revenue_hits" : {
"value" : 7479.60009765625
}
},
{
"key" : 922.0,
"doc_count" : 6,
"top_revenue_hits" : {
"value" : 5532.0
}
},
...
]
}
}
}
How can I get the query to return the entire guests
object, not only the sum amount.
When I run GET reservations/_search
it returns:
{
"hits": [
{
"_index": "reservations",
"_id": "1334620",
"_score": 1.0,
"_source": {
"id": "1334620",
"total": 110.8,
"payment": "unpaid",
"contact": {
"name": "John Doe",
"email": "[email protected]"
}
}
},
... other reservations
]
}
I want to get this to return with the sum
aggregation.
I have tried to use a top_hits
aggregation, using _source
it does return the entire guest
object but it does not show the total amount spent. And when adding _source
to the sum
aggregation it gives an error.
Can I return the entire guest
object with a sum
aggregation or is this not the correct way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设
contact.name
在映射中是关键字
。以下查询应该为您工作。I assumed that
contact.name
iskeyword
in the mapping. Following query should work for you.