Skip to content

Inner .Aggregations() with .Sum() can't get "Sum" values #1079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Dem0n2die4 opened this issue Nov 28, 2014 · 11 comments
Closed

Inner .Aggregations() with .Sum() can't get "Sum" values #1079

Dem0n2die4 opened this issue Nov 28, 2014 · 11 comments
Assignees

Comments

@Dem0n2die4
Copy link

Hello. Use nest 1.2.2 with elastic 1.3.2.

Do this request:

var histogram = client.Search( s => s
.Query( q => q.
.Filtered( qf => qf
.Query( qq => qq.MatchAll())
.Filter( f => f.Range( r => r.OnField( rf => rf.Time).Greater(from).Lower(to)))
)
)
.Aggregations( a => a.Histogram("hist", h => h.Field(f => f.Time)
.Interval(3000)
.Aggregations( agg => agg
.Sum("sizes", aggs => aggs.Field(sf => sf.Size))
)
)
);

var result = histogram.Aggs.Histogram("hist");

foreach( var interval in result.Items){
    var sizes = hour.Sum("sizes"); // in this string was an exeption something like "Aggregations in interval = null"
}
"interval" is correct,

If I do this request manualy response looks like:

{
"key": 1417168800,
"doc_count": 28,
"sizes": {
"value": 900
}
},
{
"key": 1417172400,
"doc_count": 21,
"sizes": {
"value": 1228
}
},

Don't understand what is wrong with it. Can You help me?

@Dem0n2die4
Copy link
Author

Try to do it with FacetHistogram instead FacetDateHistogram (need custom time interval) but FacetHistogram return only key, can't get value_field count Total. Facets already doesn't supported?

@gmarz
Copy link
Contributor

gmarz commented Dec 12, 2014

@Dem0n2die4 I can't quite reproduce this. Either I don't understand the issue entirely, or it may have something to do with your data?

Would you mind taking a look at this test and see if you can get it to fail?

@gmarz gmarz self-assigned this Dec 12, 2014
@Dem0n2die4
Copy link
Author

ok, thx, I'll try it later)

@Dem0n2die4
Copy link
Author

Test works fine.
Don't understand why the same code doesn't work with my data.

@Dem0n2die4
Copy link
Author

The only difference in histogram field type. It's Int, not DateTime.

@Dem0n2die4
Copy link
Author

Yep, if "StartedOn" replace with "IntValues" then there is an exception

@gmarz
Copy link
Contributor

gmarz commented Dec 23, 2014

@Dem0n2die4 thanks for looking at the test.

I was able to confirm the same thing, getting a NullReferenceException when aggregating on IntValues.

This seems to be different issue than the error you were encountering though? What is the data type of your Time field?

@Dem0n2die4
Copy link
Author

It's Int. Think that problem just in type. But if I remove geting inner aggregation values(Sum) like this:

 public void InnerSumAggregationTest()
 {
     var response = this.Client.Search<ElasticsearchProject>(s => s
         .Aggregations(a => a
             .Histogram("hist", h => h
             .Field(p => p.IntValues)
             .Interval(3000)
             .Aggregations(aa => aa
                 .Sum("sizes", sa => sa
                 .Field(p => p.LongValue)
                 )
             )
             )
         )
     );

     var hist = response.Aggs.Histogram("hist");
//     foreach (var interval in hist.Items)
//     {
//         var sizes = interval.Sum("sizes");
//     }
 }

it'll work perfect. Don't know whether it's different issue or not. But inner aggregation is null when "main" aggregation field type is Int

@Dem0n2die4
Copy link
Author

Maybe I doing something wrong, but bucket in _SetInnerAggregation which fills with selector is always null

@gmarz gmarz closed this as completed in 6fba54e Dec 26, 2014
@gmarz
Copy link
Contributor

gmarz commented Dec 26, 2014

@Dem0n2die4 I was able to get to the bottom of this. The problem was that inner aggregations were totally ignored when converting from KeyItem to HistogramItem in AggregationHelper.Histogram().

Just pushed the fix above; thank you for reporting this. 👍

@gmarz gmarz added the Bug label Dec 26, 2014
@Dem0n2die4
Copy link
Author

Thx for help)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants