Skip to content

Commit

Permalink
Add indexing and search index settings
Browse files Browse the repository at this point in the history
This commit adds indexing and search settings to index settings. These
settings allow configuring of slow logs for indexing and search, as
well as setting search idle after.

Search idle after duplicates the individual
IndexSettings::searchIdleAfter property, but this pattern is already
present e.g. IndexSettings::blocks and IndexSettings::blocksReadOnly,
IndexSettings::blocksRead, etc.

Signed-off-by: Russ Cam <russcam@canva.com>
  • Loading branch information
russcam committed Oct 16, 2023
1 parent 722b1a5 commit 9bbcf8b
Show file tree
Hide file tree
Showing 11 changed files with 1,669 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ public class IndexSettings implements JsonpSerializable {
@Nullable
private final IndexSettingsMapping mapping;

@Nullable
private final IndexSettingsIndexing indexing;

@Nullable
private final IndexSettingsSearch search;

@Nullable
private final Boolean knn;

Expand Down Expand Up @@ -280,6 +286,8 @@ private IndexSettings(Builder builder) {
this.analysis = builder.analysis;
this.settings = builder.settings;
this.mapping = builder.mapping;
this.indexing = builder.indexing;
this.search = builder.search;
this.knn = builder.knn;
this.knnAlgoParamEfSearch = builder.knnAlgoParamEfSearch;

Expand Down Expand Up @@ -748,6 +756,22 @@ public final IndexSettingsMapping mapping() {
return this.mapping;
}

/**
* API name: {@code indexing}
*/
@Nullable
public final IndexSettingsIndexing indexing() {
return this.indexing;
}

/**
* API name: {@code search}
*/
@Nullable
public final IndexSettingsSearch search() {
return this.search;
}

/**
* API name: {@code knn}
*/
Expand Down Expand Up @@ -1054,6 +1078,16 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.writeKey("mapping");
this.mapping.serialize(generator, mapper);

}
if (this.indexing != null) {
generator.writeKey("indexing");
this.indexing.serialize(generator, mapper);

}
if (this.search != null) {
generator.writeKey("search");
this.search.serialize(generator, mapper);

}
if (this.knn != null) {
generator.writeKey("knn");
Expand Down Expand Up @@ -1240,6 +1274,12 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<I
@Nullable
private IndexSettingsMapping mapping;

@Nullable
private IndexSettingsIndexing indexing;

@Nullable
private IndexSettingsSearch search;

@Nullable
private Boolean knn;

Expand Down Expand Up @@ -1821,6 +1861,36 @@ public final Builder mapping(Function<IndexSettingsMapping.Builder, ObjectBuilde
return this.mapping(fn.apply(new IndexSettingsMapping.Builder()).build());
}

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

/**
* API name: {@code indexing}
*/
public final Builder indexing(Function<IndexSettingsIndexing.Builder, ObjectBuilder<IndexSettingsIndexing>> fn) {
return this.indexing(fn.apply(new IndexSettingsIndexing.Builder()).build());
}

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

/**
* API name: {@code search}
*/
public final Builder search(Function<IndexSettingsSearch.Builder, ObjectBuilder<IndexSettingsSearch>> fn) {
return this.search(fn.apply(new IndexSettingsSearch.Builder()).build());
}

/**
* Builds a {@link IndexSettings}.
*
Expand Down Expand Up @@ -1995,6 +2065,8 @@ protected static void setupIndexSettingsDeserializer(ObjectDeserializer<IndexSet
op.add(Builder::analysis, IndexSettingsAnalysis._DESERIALIZER, "analysis", "index.analysis");
op.add(Builder::settings, IndexSettings._DESERIALIZER, "settings");
op.add(Builder::mapping, IndexSettingsMapping._DESERIALIZER, "mapping");
op.add(Builder::indexing, IndexSettingsIndexing._DESERIALIZER, "indexing");
op.add(Builder::search, IndexSettingsSearch._DESERIALIZER, "search");
op.add(Builder::knn, JsonpDeserializer.booleanDeserializer(), "knn", "index.knn");
op.add(
Builder::knnAlgoParamEfSearch,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.client.opensearch.indices;

import jakarta.json.stream.JsonGenerator;
import java.util.function.Function;
import javax.annotation.Nullable;
import org.opensearch.client.json.*;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;

@JsonpDeserializable
public class IndexSettingsIndexing implements JsonpSerializable {
@Nullable
private final IndexingSlowlog slowlog;

// ---------------------------------------------------------------------------------------------

private IndexSettingsIndexing(Builder builder) {

this.slowlog = builder.slowlog;

}

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

/**
* API name: {@code slowlog}
*/
@Nullable
public final IndexingSlowlog slowlog() {
return this.slowlog;
}

/**
* Serialize this object to JSON.
*/
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
generator.writeStartObject();
serializeInternal(generator, mapper);
generator.writeEnd();
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

if (this.slowlog != null) {
generator.writeKey("slowlog");
this.slowlog.serialize(generator, mapper);

}

}

// ---------------------------------------------------------------------------------------------

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

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<IndexSettingsIndexing> {
@Nullable
private IndexingSlowlog slowlog;

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

/**
* API name: {@code slowlog}
*/
public final Builder slowlog(Function<IndexingSlowlog.Builder, ObjectBuilder<IndexingSlowlog>> fn) {
return this.slowlog(fn.apply(new IndexingSlowlog.Builder()).build());
}

/**
* Builds a {@link IndexSettingsIndexing}.
*
* @throws NullPointerException
* if some of the required fields are null.
*/
public IndexSettingsIndexing build() {
_checkSingleUse();

return new IndexSettingsIndexing(this);
}
}

// ---------------------------------------------------------------------------------------------

/**
* Json deserializer for {@link IndexSettingsIndexing}
*/
public static final JsonpDeserializer<IndexSettingsIndexing> _DESERIALIZER = ObjectBuilderDeserializer.lazy(
Builder::new,
IndexSettingsIndexing::setupSettingsSearchDeserializer
);

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

op.add(Builder::slowlog, IndexingSlowlog._DESERIALIZER, "slowlog");

}

}
Loading

0 comments on commit 9bbcf8b

Please sign in to comment.