1

I created an AggregationsHelper object and I called .Filter method on it

 var aggr = new AggregationsHelper();
 aggr .Filter("test");

I get a null exception when calling the .Filter function. Do I have to initiate the object somehow?

EDIT:

As pointed out by @Val, I have to pass a dictionary to the object via the constructor

My real question is how to mock such complex ElasticSearch aggregation query:

    var res = ElasticClient.Search<DataRecord>(s => s
            .SearchType(SearchType.Count)
            .Aggregations(a => a.Filter(
                "histIdFilter",
                f => f.Filter(
                    f2 => f2.Term(
                        t => t.HistoryId,
                        groupId))
            .Aggregations(ag => ag.Filter("timeRangeFilter", fg => fg.Filter(fg2 => fg2.Range(i => i.OnField(b => b.DateTime))))))));

    // Applying filter
    var ah = res.Aggs;
    var histIdAgg = ah.Filter("histIdFilter");
    var timeRangeAgg = histIdAgg.Filter("timeRangeFilter");

I successfully managed to mock the .Aggr property of the query response, using

datResp.SetupGet(x => x.Aggs).Returns(ah.Object);

but when I call .Filter on the ah object I get a null exception like if the internal dictionary was not set for some reason

1 Answer 1

1

It's because when creating an AggregationsHelper without passing a dictionary, you'll get a null pointer exception on this line. Try like this instead:

var temp = new Dictionary<string, IAggregation>();
var aggr = new AggregationsHelper(temp);
aggr.Filter("test");
Sign up to request clarification or add additional context in comments.

1 Comment

brilliant. This lead to my real question which is another one. I need to mock a NEST ElasticSearch query. Please, see my edit for the question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.