Notnull check on template is blocking the creation of composite template request
Hi Team,
Please find the below code -
https://github.com/opensearch-project/opensearch-java/blame/bb0fa12098ed3ef8b785a4560d6d962b2726a0d2/java-client/src/main/java/org/opensearch/client/opensearch/cluster/PutComponentTemplateRequest.java#L107
this.template = ApiTypeHelper.requireNonNull(builder.template, this, "template");
This check is not needed and the whole purpose for us is to create the template object using builder. Infact see the sample code where "template" is not explicitly created part of the builder.
- https://github.com/opensearch-project/opensearch-java/blob/main/samples/src/main/java/org/opensearch/client/samples/IndexTemplates.java#L49
- https://github.com/opensearch-project/opensearch-java/blob/main/samples/src/main/java/org/opensearch/client/samples/IndexTemplates.java#L69
Currently due to this check, a requireNonNull error is thrown and we cannot use the PutComponentTemplateRequest object in building component templates via RestClient java api.
Error below
Exception in thread "main" org.opensearch.client.util.MissingRequiredPropertyException: Missing required property 'PutComponentTemplateRequest.template' at org.opensearch.client.util.ApiTypeHelper.requireNonNull(ApiTypeHelper.java:90) at org.opensearch.client.opensearch.cluster.PutComponentTemplateRequest.<init>(PutComponentTemplateRequest.java:107) at org.opensearch.client.opensearch.cluster.PutComponentTemplateRequest.<init>(PutComponentTemplateRequest.java:67) at org.opensearch.client.opensearch.cluster.PutComponentTemplateRequest$Builder.build(PutComponentTemplateRequest.java:464) at org.opensearch.client.opensearch.cluster.PutComponentTemplateRequest$Builder.build(PutComponentTemplateRequest.java:262) at org.opensearch.client.opensearch.cluster.PutComponentTemplateRequest.of(PutComponentTemplateRequest.java:113) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrap.invoke(StaticMetaMethodSite.java:131) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:89) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139) at App.main(App.groovy:82)
Hello Team,
I was trying to understand the issue related to PutComponentTemplateRequest.
Is template always required, or can it be optional?
What happens if we pass an empty template? Does OpenSearch handle it properly, or does it cause issues?
Understanding this will help determine whether the requireNonNull check is necessary.
@nibin Can you help me with understanding this?
This has been clarified in v3.0.0 of the client, the aliases, mappings, and settings fields directly defined on PutComponentTemplateRequest were incorrect, they should have always been nested under template as the sample code uses, hence why template was required. The superfluous non-functioning fields have been removed.