1
votes

I'm new to ElasticSearch and it's NEST client for C#. Apparently the min_doc_count for composite aggregations is not implemented, and I should use a script in the request to achieve the result, see: https://github.com/elastic/elasticsearch/issues/32452#issuecomment-408769861.

However when I try to implement this in C#, I'm getting the following error:

"Type: class_cast_exception Reason: "Cannot cast from [boolean] to [java.lang.Number].""

My code looks like this:

ISearchResponse<FooBar> duplicateBucket = _elasticClient.Search<FooBar>(
    s => s
        .Aggregations(a => a
            .Composite("dupe_bucket", c => c
                .Sources(b => b
                    .Terms("foo", x => x
                        .Field("foo"))
                    .Terms("bar", x => x
                         .Field("bar")))
                .Size(1000)
                .Aggregations(e => e
                    .BucketScript("bucket_selector", d => d
                        .BucketsPath(f => f
                            .Add("counter", "_count"))
                        .Script("params.counter > 1"))))));

If I remove the second aggregation, the call will succeed, so clearly I'm doing something wrong in the BucketScript part.

Any help would be appreciated!

1
What does the generated query look like?stuartd
I think you want to use BucketSelector instead of BucketScript.Val
@Val Yeah, that did the trick, thanks !Robinnaiitor

1 Answers

1
votes

I think you want to use BucketSelector instead of BucketScript

            .Aggregations(e => e
    -->          .BucketSelector("bucket_selector", d => d
                    .BucketsPath(f => f
                        .Add("counter", "_count"))
                    .Script("params.counter > 1"))))));