// Path: src/main/java/org/codelibs/fess/suggest/exception/SuggestSettingsException.java
// public class SuggestSettingsException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
// 
//     public SuggestSettingsException(final String msg) {
//         super(msg);
//     }
// 
//     public SuggestSettingsException(final Throwable cause) {
//         super(cause);
//     }
// 
//     public SuggestSettingsException(final String msg, final Throwable cause) {
//         super(msg, cause);
//     }
// }
// 
// Path: src/main/java/org/codelibs/fess/suggest/exception/SuggesterException.java
// public class SuggesterException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
// 
//     public SuggesterException(final String msg) {
//         super(msg);
//     }
// 
//     public SuggesterException(final Throwable cause) {
//         super(cause);
//     }
// 
//     public SuggesterException(final String msg, final Throwable cause) {
//         super(msg, cause);
//     }
// }


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.suggest.exception.SuggestSettingsException;
import org.codelibs.fess.suggest.exception.SuggesterException;
import org.opensearch.action.get.GetResponse;
import org.opensearch.client.Client;
import org.opensearch.common.collect.Tuple;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.index.IndexNotFoundException;
    public void init() {
        if (initialized) {
            return;
        }
        initialized = true;
        initialize(initialSettings);
        new AnalyzerSettings(client, this, settingsIndexName).init();
    }

    private void initialize(final Map<String, Object> initialSettings) {
        boolean doIndexCreate = false;
        boolean doCreate = false;
        try {
            final GetResponse getResponse =
                    client.prepareGet().setIndex(settingsIndexName).setId(settingsId).execute().actionGet(getSearchTimeout());

            if (!getResponse.isExists()) {
                doCreate = true;
            }
        } catch (final IndexNotFoundException e) {
            doIndexCreate = true;
            doCreate = true;
        }

        if (doCreate) {
            if (doIndexCreate) {
                try {
                    client.admin().indices().prepareCreate(settingsIndexName).setSettings(loadIndexSettings(), XContentType.JSON).execute()
                            .actionGet(getIndicesTimeout());
                } catch (final IOException e) {
// Path: src/main/java/org/codelibs/fess/suggest/exception/SuggestSettingsException.java
// public class SuggestSettingsException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
// 
//     public SuggestSettingsException(final String msg) {
//         super(msg);
//     }
// 
//     public SuggestSettingsException(final Throwable cause) {
//         super(cause);
//     }
// 
//     public SuggestSettingsException(final String msg, final Throwable cause) {
//         super(msg, cause);
//     }
// }
// 
// Path: src/main/java/org/codelibs/fess/suggest/exception/SuggesterException.java
// public class SuggesterException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
// 
//     public SuggesterException(final String msg) {
//         super(msg);
//     }
// 
//     public SuggesterException(final Throwable cause) {
//         super(cause);
//     }
// 
//     public SuggesterException(final String msg, final Throwable cause) {
//         super(msg, cause);
//     }
// }


// Path: src/main/java/org/codelibs/fess/suggest/settings/SuggestSettings.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.suggest.exception.SuggestSettingsException;
import org.codelibs.fess.suggest.exception.SuggesterException;
import org.opensearch.action.get.GetResponse;
import org.opensearch.client.Client;
import org.opensearch.common.collect.Tuple;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.index.IndexNotFoundException;

    public void init() {
        if (initialized) {
            return;
        }
        initialized = true;
        initialize(initialSettings);
        new AnalyzerSettings(client, this, settingsIndexName).init();
    }

    private void initialize(final Map<String, Object> initialSettings) {
        boolean doIndexCreate = false;
        boolean doCreate = false;
        try {
            final GetResponse getResponse =
                    client.prepareGet().setIndex(settingsIndexName).setId(settingsId).execute().actionGet(getSearchTimeout());

            if (!getResponse.isExists()) {
                doCreate = true;
            }
        } catch (final IndexNotFoundException e) {
            doIndexCreate = true;
            doCreate = true;
        }

        if (doCreate) {
            if (doIndexCreate) {
                try {
                    client.admin().indices().prepareCreate(settingsIndexName).setSettings(loadIndexSettings(), XContentType.JSON).execute()
                            .actionGet(getIndicesTimeout());
                } catch (final IOException e) {
                    throw new SuggesterException(e);