This repository contains Java code samples for working with OpenSearch, demonstrating various features and capabilities of the OpenSearch Java client.
OpenSearchSamples/
- Maven project containing the OpenSearch Java samplessrc/test/java/
- Test classes demonstrating OpenSearch featuresGettingStarted/
- Basic examples for getting started with OpenSearchKeywordDemo/
- Examples demonstrating keyword field mapping and searchingKeywordIndexingTests.java
- Tests for keyword field indexingKeywordSearchingTests.java
- Tests for keyword field searchingKeywordAggregationTests.java
- Tests for keyword field aggregationsKeywordScriptingTests.java
- Tests for keyword field scriptingKeywordSortingTests.java
- Tests for keyword field sorting
TextDemo/
- Examples demonstrating text field mapping and analysisTextIndexingTests.java
- Tests for text field indexingTextTests.java
- Tests for text field analysis and searching
TestExtensions/
- JUnit 5 extensions for managing OpenSearch resourcesTestInfrastructure/
- Helper classes for creating and managing test indices
infrastructure/
- Docker Compose configuration for running OpenSearch locally
- Java 17 or later
- Maven
- Docker and Docker Compose
- Start the OpenSearch container:
cd OpenSearchSamples/infrastructure
docker-compose up -d
- Run the tests:
cd OpenSearchSamples
mvn test
Basic tests demonstrating how to connect to OpenSearch, check cluster health, and create/delete indices.
Tests demonstrating how keyword fields work in OpenSearch:
- Keyword fields are indexed as a single token without analysis
- Exact matching with term queries
- Filtering with boolean queries
- Scoring with constant score queries
- Aggregations (terms, cardinality, top hits, field collapsing, adjacency matrix)
- Scripting (creating scripted fields, using parameters in scripts)
- Sorting (script-based sorting, field sorting, lexicographical vs. numerical sorting)
Tests demonstrating how text fields work in OpenSearch:
- Text fields are analyzed using the standard analyzer by default
- Configuring analyzers with stop words
- Configuring analyzers with maximum token length
- Searching text fields with term queries
This project is licensed under the MIT License - see the LICENSE file for details.