forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add similarity settings when using CreateIndexRequest
- Loading branch information
ritty (박지수)
committed
May 12, 2024
1 parent
d092df5
commit 27ac012
Showing
4 changed files
with
346 additions
and
0 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
...lient/src/main/java/org/opensearch/client/opensearch/indices/IndexSettingsSimilarity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
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); | ||
|
||
} | ||
|
||
} |
142 changes: 142 additions & 0 deletions
142
...t/src/main/java/org/opensearch/client/opensearch/indices/IndexSettingsSimilarityBm25.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.function.Function; | ||
|
||
@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"); | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
...rc/main/java/org/opensearch/client/opensearch/indices/IndexSettingsSimilarityBoolean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.opensearch.client.opensearch.indices; | ||
|
||
import jakarta.json.stream.JsonGenerator; | ||
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; | ||
|
||
import java.util.function.Function; | ||
|
||
@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"); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...rc/main/java/org/opensearch/client/opensearch/indices/IndexSettingsSimilarityVariant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
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); | ||
} | ||
|
||
} |