1

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!

3
  • What does the generated query look like? Commented Sep 23, 2019 at 12:40
  • 1
    I think you want to use BucketSelector instead of BucketScript. Commented Sep 23, 2019 at 12:43
  • @Val Yeah, that did the trick, thanks ! Commented Sep 23, 2019 at 12:53

1 Answer 1

1

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"))))));
Sign up to request clarification or add additional context in comments.

Comments

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.