elastic/elasticsearch-java

Allow method chaining in Processor.Builder

gregorko opened this issue · 3 comments

Description

Return type of methods in Processor.Builder prevent method chaining.

Example:

co.elastic.clients.elasticsearch.ingest.Processor.of(b -> b
    .attachment(a -> a)
    .remove(r -> r)
)

This will not compile since attachment() and all other methods return ObjectBuilder<Processor> instead of Builder

Hello! The reason why Processor doesn't allow chaining is that APIs that use it usually require a List<Processor>, so that's how you can set multiple processors. Is there a specific case where you would use multiple processors outside a list? Or could you point me to the API you're trying to use? Maybe there's a case we missed, let me know!

This is how I use it now:

        client.ingest().putPipeline(b -> b
            .processors(p -> {
                    p.attachment(a -> a);
                    p.remove(r -> r);
                    return p;
                }));

but compared to other APIs it would feel more natural to use it like this:

        client.ingest().putPipeline(b -> b
            .processors(p -> p
                    .attachment(a -> a)
                    .remove(r -> r);
            ))

Hmm I get it now, it does feel more natural. The issue we have with implementing this is that it's a significant change to the client code generator, and we'd also need to evaluate how it would affect similar classes, so we'll evaluate this as a possible enhancement!