Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/amitsaxena098/OpenKnowledgeStream/llms.txt

Use this file to discover all available pages before exploring further.

OpenSearch connectivity is provided by the OpensearchConfig Spring @Configuration class in the opensearch-wiki-indexer module. It constructs an OpenSearchClient bean that is injected into OpensearchIndexer, which handles all document writes. No Spring Boot auto-configuration is used — the client is built by hand using the opensearch-java 2.19.0 SDK.
The current configuration connects to OpenSearch over plain HTTP with no authentication. Before deploying to any non-local environment, secure your OpenSearch cluster with TLS and user credentials, and update OpensearchConfig.java accordingly.

Connection

host
string
default:"localhost"
The hostname or IP address of the OpenSearch node. Passed as the first argument to new HttpHost(...) in RestClient.builder().
port
integer
default:"9200"
The HTTP port on which OpenSearch is listening. Passed as the second argument to new HttpHost(...). OpenSearch defaults to 9200.
transport
string
default:"RestClientTransport"
The transport layer wrapping the low-level RestClient. RestClientTransport serializes and deserializes JSON using JacksonJsonpMapper.
json mapper
string
default:"JacksonJsonpMapper"
The JSON mapper used by RestClientTransport to convert between Java objects and the OpenSearch wire format. Backed by Jackson ObjectMapper.
OpensearchConfig.java
package WikiIndexer.config;

import org.opensearch.client.transport.rest_client.RestClientTransport;
import org.opensearch.client.opensearch.OpenSearchClient;
import org.opensearch.client.json.jackson.JacksonJsonpMapper;
import org.apache.http.HttpHost;
import org.opensearch.client.RestClient;
import org.opensearch.client.transport.OpenSearchTransport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OpensearchConfig {

    @Bean
    public OpenSearchClient openSearchClient() {
        RestClient restClient =
                RestClient.builder(
                        new HttpHost("localhost", 9200)
                ).build();

        OpenSearchTransport transport =
                new RestClientTransport(
                        restClient,
                        new JacksonJsonpMapper()
                );

        return new OpenSearchClient(transport);
    }
}

Index

Documents are written by OpensearchIndexer.index(), which uses the OpenSearchClient bean provided by OpensearchConfig.
index
string
default:"wiki-changes"
The OpenSearch index into which Change documents are written. The index name is hardcoded in OpensearchIndexer as "wiki-changes". OpenSearch will create the index automatically on the first write if it does not already exist.
document id
string
Each document is keyed by the title field of the Change model (i.e., .id(change.getTitle())). This means subsequent changes to the same Wikipedia page title will overwrite the existing document, acting as an upsert.
OpensearchIndexer.java
package WikiIndexer.index;

import Wikicommon.models.Change;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.opensearch.client.opensearch.OpenSearchClient;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Slf4j
public class OpensearchIndexer {

    private final OpenSearchClient openSearchClient;

    public void index(Change change) throws Exception {
        openSearchClient.index(i -> i
                .index("wiki-changes")
                .id(change.getTitle())
                .document(change));
        log.info("Indexed Title: {}", change.getTitle());
    }
}
Because the document ID is derived from the page title, each Wikipedia article has at most one document in the wiki-changes index at any time. Only the most recent change event for a given title is retained.

Changing the host or port

To connect to a different OpenSearch instance, edit the HttpHost constructor call in OpensearchConfig.java:
OpensearchConfig.java — custom host example
RestClient restClient =
        RestClient.builder(
                new HttpHost("opensearch.example.com", 9200)
        ).build();
Replace "opensearch.example.com" and 9200 with the hostname and port of your OpenSearch node.

Build docs developers (and LLMs) love