zeusfsx
(Саша Коровій)
April 9, 2021, 6:49am
1
Hi, I have documents in the index with the field sentimental_keywords:
sentimental_keywords: [
{
rate: 0.2857143,
keyword: "manager"
},
...
{
rate: -0.333333343,
keyword: "project"
},
]
When I do terms aggregations :
"aggs": {
sentimental_keywords": {
"terms": {
"field" : "sentimental_keywords.keyword.keyword",
"size": 100
}
}
I get the result:
'buckets': [
{'key': 'manager', 'doc_count': 444},
{'key': 'project', 'doc_count': 373}
]
I also want to add each term (key), the value of the rate, for example, get next result:
'buckets': [
{'key': 'manager', 'doc_count': 444, 'rate': { 'value': 0.2857143}},
{'key': 'project', 'doc_count': 373, 'rate': { 'value': -0.333333343}}
]
Do you have any suggestions?
dadoonet
(David Pilato)
April 9, 2021, 7:07am
2
I'm not sure if that would fit with what you're looking for as aggregations are meant to aggregate documents and not providing individual values.
So what about a avg
or a max
agg as a sub aggregation of your terms
agg?
zeusfsx
(Саша Коровій)
April 9, 2021, 7:14am
3
I've tried to use sub aggregation for a rate like max
or avg
, it returns the average or max rate for a document where term from top-level aggs
meets.
zeusfsx
(Саша Коровій)
April 9, 2021, 8:07am
4
I solved it by using sub aggregate terms for rate value
"aggs": {
"sentimental_keywords": {
"terms": {
"field" : "sentimental_keywords.keyword.keyword",
"size": 10
},
"aggs": {
"rate": {
"terms": {
"field": "calculation.sentimental_keywords.rate",
"size": 1
}
}
}
}
}
In the result I get what I wanted:
{
'key': 'project',
'doc_count': 371,
'rate': {
'doc_count_error_upper_bound': 66,
'sum_other_doc_count': 1789,
'buckets': [{'key': -0.333333343, 'doc_count': 371}]
}
}
1 Like
dadoonet
(David Pilato)
April 9, 2021, 8:56am
5
I'm surprised that this will work with more data.
system
(system)
Closed
May 7, 2021, 8:56am
6
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.