Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add similarity settings when using CreateIndexRequest #989

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package org.opensearch.client.opensearch.indices;


import jakarta.json.stream.JsonGenerator;
import java.util.function.Function;
import org.opensearch.client.json.JsonEnum;
import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.JsonpSerializable;
import org.opensearch.client.json.ObjectBuilderDeserializer;
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.util.ApiTypeHelper;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;
import org.opensearch.client.util.TaggedUnion;



@JsonpDeserializable
public class IndexSettingsSimilarity implements TaggedUnion<IndexSettingsSimilarity.Kind, IndexSettingsSimilarityVariant>, JsonpSerializable {


public enum Kind implements JsonEnum {
Bm25("BM25"),

Boolean("boolean"),

;

private final String jsonValue;

Kind(String jsonValue) {
this.jsonValue = jsonValue;
}

public String jsonValue() {
return this.jsonValue;
}

}

private final Kind _kind;
private final IndexSettingsSimilarityVariant _value;

public final Kind _kind() {
return _kind;
}

public final IndexSettingsSimilarityVariant _get() {
return _value;
}

public IndexSettingsSimilarity(IndexSettingsSimilarityVariant value) {

this._kind = ApiTypeHelper.requireNonNull(value._settingsSimilarityKind(), this, "<variant kind>");
this._value = ApiTypeHelper.requireNonNull(value, this, "<variant value>");

}

private IndexSettingsSimilarity(Builder builder) {

this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, "<variant kind>");
this._value = ApiTypeHelper.requireNonNull(builder._value, builder, "<variant value>");

}

public static IndexSettingsSimilarity of(Function<Builder, ObjectBuilder<IndexSettingsSimilarity>> fn) {
return fn.apply(new Builder()).build();
}


public void serialize(JsonGenerator generator, JsonpMapper mapper) {
mapper.serialize(_value, generator);
}

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<IndexSettingsSimilarity> {
private Kind _kind;
private IndexSettingsSimilarityVariant _value;

public ObjectBuilder<IndexSettingsSimilarity> bm25(IndexSettingsSimilarityBm25 v) {
this._kind = Kind.Bm25;
this._value = v;
return this;
}

public ObjectBuilder<IndexSettingsSimilarity> bm25(
Function<IndexSettingsSimilarityBm25.Builder, ObjectBuilder<IndexSettingsSimilarityBm25>> fn) {
return this.bm25(fn.apply(new IndexSettingsSimilarityBm25.Builder()).build());
}

public ObjectBuilder<IndexSettingsSimilarity> boolean_(IndexSettingsSimilarityBoolean v) {
this._kind = Kind.Boolean;
this._value = v;
return this;
}

public ObjectBuilder<IndexSettingsSimilarity> boolean_(
Function<IndexSettingsSimilarityBoolean.Builder, ObjectBuilder<IndexSettingsSimilarityBoolean>> fn) {
return this.boolean_(fn.apply(new IndexSettingsSimilarityBoolean.Builder()).build());
}


@Override
public IndexSettingsSimilarity build() {
_checkSingleUse();
return new IndexSettingsSimilarity(this);
}
}

public static final JsonpDeserializer<IndexSettingsSimilarity> _DESERIALIZER = ObjectBuilderDeserializer
.lazy(Builder::new, IndexSettingsSimilarity::setupIndexSettingsSimilarityDeserializer, Builder::build);

protected static void setupIndexSettingsSimilarityDeserializer(ObjectDeserializer<Builder> op) {

op.add(Builder::bm25, IndexSettingsSimilarityBm25._DESERIALIZER, "BM25");
op.add(Builder::boolean_, IndexSettingsSimilarityBoolean._DESERIALIZER, "boolean");

op.setTypeProperty("type", null);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package org.opensearch.client.opensearch.indices;

import jakarta.json.stream.JsonGenerator;
import javax.annotation.Nullable;
import java.util.function.Function;
import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.JsonpSerializable;
import org.opensearch.client.json.ObjectBuilderDeserializer;
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;


@JsonpDeserializable
public class IndexSettingsSimilarityBm25 implements IndexSettingsSimilarityVariant, JsonpSerializable {

@Nullable
private final Double b;

@Nullable
private final Boolean discountOverlaps;

@Nullable
private final Double k1;


private IndexSettingsSimilarityBm25(Builder builder) {

this.b = builder.b;
this.discountOverlaps = builder.discountOverlaps;
this.k1 = builder.k1;

}

public static IndexSettingsSimilarityBm25 of(Function<Builder, ObjectBuilder<IndexSettingsSimilarityBm25>> fn) {
return fn.apply(new Builder()).build();
}


@Override
public IndexSettingsSimilarity.Kind _settingsSimilarityKind() {
return IndexSettingsSimilarity.Kind.Bm25;
}

@Override
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
generator.writeStartObject();
serializeInternal(generator, mapper);
generator.writeEnd();
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

generator.write("type", "BM25");

if (this.b != null) {
generator.writeKey("b");
generator.write(this.b);

}
if (this.discountOverlaps != null) {
generator.writeKey("discount_overlaps");
generator.write(this.discountOverlaps);

}
if (this.k1 != null) {
generator.writeKey("k1");
generator.write(this.k1);

}

}

/**
* Builder for {@link IndexSettingsSimilarityBm25}.
*/

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<IndexSettingsSimilarityBm25> {

@Nullable
private Double b;

@Nullable
private Boolean discountOverlaps;

@Nullable
private Double k1;

/**
* API name: {@code b}
*/
public final Builder b(@Nullable Double value) {
this.b = value;
return this;
}

/**
* API name: {@code discount_overlaps}
*/
public final Builder discountOverlaps(@Nullable Boolean value) {
this.discountOverlaps = value;
return this;
}

/**
* API name: {@code k1}
*/
public final Builder k1(@Nullable Double value) {
this.k1 = value;
return this;
}

/**
* Builds a {@link IndexSettingsSimilarityBm25}.
*
* @throws NullPointerException if some of the required fields are null.
*/

public IndexSettingsSimilarityBm25 build() {
_checkSingleUse();

return new IndexSettingsSimilarityBm25(this);
}
}

public static final JsonpDeserializer<IndexSettingsSimilarityBm25> _DESERIALIZER = ObjectBuilderDeserializer.lazy(
Builder::new,
IndexSettingsSimilarityBm25::setupIndexSettingsSimilarityBm25Deserializer
);

protected static void setupIndexSettingsSimilarityBm25Deserializer(ObjectDeserializer<IndexSettingsSimilarityBm25.Builder> op) {

op.add(Builder::b, JsonpDeserializer.doubleDeserializer(), "b");
op.add(Builder::discountOverlaps, JsonpDeserializer.booleanDeserializer(), "discount_overlaps");
op.add(Builder::k1, JsonpDeserializer.doubleDeserializer(), "k1");

op.ignore("type");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.opensearch.client.opensearch.indices;


import jakarta.json.stream.JsonGenerator;
import java.util.function.Function;
import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.JsonpSerializable;
import org.opensearch.client.json.ObjectBuilderDeserializer;
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;


@JsonpDeserializable
public class IndexSettingsSimilarityBoolean implements IndexSettingsSimilarityVariant, JsonpSerializable {

private IndexSettingsSimilarityBoolean(Builder builder) {

}

public static IndexSettingsSimilarityBoolean of(Function<Builder, ObjectBuilder<IndexSettingsSimilarityBoolean>> fn) {
return fn.apply(new Builder()).build();
}


@Override
public IndexSettingsSimilarity.Kind _settingsSimilarityKind() {
return IndexSettingsSimilarity.Kind.Boolean;
}

@Override
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
generator.writeStartObject();
serializeInternal(generator, mapper);
generator.writeEnd();
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

generator.write("type", "boolean");

}


/**
* Builder for {@link IndexSettingsSimilarityBoolean}.
*/

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<IndexSettingsSimilarityBoolean> {

public IndexSettingsSimilarityBoolean build() {
_checkSingleUse();

return new IndexSettingsSimilarityBoolean(this);
}
}


public static final JsonpDeserializer<IndexSettingsSimilarityBoolean> _DESERIALIZER = ObjectBuilderDeserializer.lazy(
Builder::new,
IndexSettingsSimilarityBoolean::setupIndexSettingsSimilarityBooleanDeserializer
);

protected static void setupIndexSettingsSimilarityBooleanDeserializer(ObjectDeserializer<IndexSettingsSimilarityBoolean.Builder> op) {

op.ignore("type");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.opensearch.client.opensearch.indices;


import org.opensearch.client.json.JsonpSerializable;

public interface IndexSettingsSimilarityVariant extends JsonpSerializable {

IndexSettingsSimilarity.Kind _settingsSimilarityKind();

default IndexSettingsSimilarity _toSettingsSimilarity() {
return new IndexSettingsSimilarity(this);
}

}
Loading