CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-opensearch--opensearch

OpenSearch is a distributed, RESTful search and analytics engine built as a community-driven fork of Elasticsearch.

Pending
Overview
Eval results
Files

index-management.mddocs/

Index Management

APIs for creating, configuring, and managing indices including mappings, settings, and index lifecycle operations. OpenSearch provides comprehensive control over index structure, field definitions, analysis configuration, and operational maintenance.

Capabilities

Index CRUD Operations

Core operations for creating, reading, updating, and deleting indices.

/**
 * Request to create a new index with optional settings and mappings
 */
class CreateIndexRequest extends ActionRequest {
    /**
     * Create index request for specified index name
     * @param index Name of the index to create
     */
    CreateIndexRequest(String index);
    
    /**
     * Set index settings
     * @param settings Index configuration settings
     */
    CreateIndexRequest settings(Settings settings);
    
    /**
     * Set index settings from map
     * @param source Settings as key-value pairs
     */
    CreateIndexRequest settings(Map<String, Object> source);
    
    /**
     * Set index mapping for document structure
     * @param source Mapping definition as JSON string
     * @param xContentType Content type of the mapping source
     */
    CreateIndexRequest mapping(String source, XContentType xContentType);
    
    /**
     * Set index mapping from map
     * @param source Mapping definition as key-value pairs
     */
    CreateIndexRequest mapping(Map<String, Object> source);
    
    /**
     * Add index alias
     * @param alias Alias configuration
     */
    CreateIndexRequest alias(Alias alias);
    
    /**
     * Set request timeout
     * @param timeout Operation timeout
     */
    CreateIndexRequest timeout(String timeout);
    
    /**
     * Set cluster manager node timeout
     * @param clusterManagerNodeTimeout Timeout for cluster manager operations
     */
    CreateIndexRequest clusterManagerNodeTimeout(String clusterManagerNodeTimeout);
    
    /**
     * Get index name
     */
    String index();
    
    /**
     * Get configured settings
     */
    Settings settings();
}

/**
 * Response for index creation operations
 */
class CreateIndexResponse extends ActionResponse {
    /**
     * Check if index creation was acknowledged
     */
    boolean isAcknowledged();
    
    /**
     * Check if shards were acknowledged before timeout
     */
    boolean isShardsAcknowledged();
    
    /**
     * Get created index name
     */
    String index();
}

/**
 * Request to delete one or more indices
 */
class DeleteIndexRequest extends ActionRequest {
    /**
     * Create delete request for specified indices
     * @param indices Index names to delete
     */
    DeleteIndexRequest(String... indices);
    
    /**
     * Set request timeout
     * @param timeout Operation timeout
     */
    DeleteIndexRequest timeout(String timeout);
    
    /**
     * Set cluster manager node timeout
     * @param clusterManagerNodeTimeout Timeout for cluster manager operations
     */
    DeleteIndexRequest clusterManagerNodeTimeout(String clusterManagerNodeTimeout);
    
    /**
     * Get indices to delete
     */
    String[] indices();
}

/**
 * Request to get index information and metadata
 */
class GetIndexRequest extends ActionRequest {
    /**
     * Create get index request for specified indices
     * @param indices Index names to retrieve information for
     */
    GetIndexRequest(String... indices);
    
    /**
     * Include settings in response
     * @param includeSettings Whether to include index settings
     */
    GetIndexRequest includeSettings(boolean includeSettings);
    
    /**
     * Include mappings in response
     * @param includeMappings Whether to include index mappings
     */
    GetIndexRequest includeMappings(boolean includeMappings);
    
    /**
     * Include aliases in response
     * @param includeAliases Whether to include index aliases
     */
    GetIndexRequest includeAliases(boolean includeAliases);
    
    /**
     * Get target indices
     */
    String[] indices();
}

/**
 * Response containing index information and metadata
 */
class GetIndexResponse extends ActionResponse {
    /**
     * Get index names included in response
     */
    String[] getIndices();
    
    /**
     * Get settings for specific index
     * @param index Index name
     */
    Settings getSettings(String index);
    
    /**
     * Get mappings for specific index
     * @param index Index name
     */
    MappingMetadata getMappings(String index);
    
    /**
     * Get aliases for specific index
     * @param index Index name
     */
    List<AliasMetadata> getAliases(String index);
    
    /**
     * Get all settings as map
     */
    Map<String, Settings> getSettings();
    
    /**
     * Get all mappings as map
     */
    Map<String, MappingMetadata> getMappings();
}

Index Settings Management

APIs for configuring and updating index-level settings.

/**
 * Request to update index settings for existing indices
 */
class UpdateSettingsRequest extends ActionRequest {
    /**
     * Create update settings request for specified indices
     * @param indices Index names to update settings for
     */
    UpdateSettingsRequest(String... indices);
    
    /**
     * Set new settings to apply
     * @param settings Settings configuration to update
     */
    UpdateSettingsRequest settings(Settings settings);
    
    /**
     * Set settings from map
     * @param source Settings as key-value pairs
     */
    UpdateSettingsRequest settings(Map<String, Object> source);
    
    /**
     * Set settings from JSON string
     * @param source Settings as JSON string
     * @param xContentType Content type of the settings source
     */
    UpdateSettingsRequest settings(String source, XContentType xContentType);
    
    /**
     * Set request timeout
     * @param timeout Operation timeout
     */
    UpdateSettingsRequest timeout(String timeout);
    
    /**
     * Get target indices
     */
    String[] indices();
    
    /**
     * Get settings to update
     */
    Settings settings();
}

/**
 * Request to retrieve current index settings
 */
class GetSettingsRequest extends ActionRequest {
    /**
     * Create get settings request for specified indices
     * @param indices Index names to get settings for
     */
    GetSettingsRequest(String... indices);
    
    /**
     * Set specific setting names to retrieve
     * @param names Setting names to include in response
     */
    GetSettingsRequest names(String... names);
    
    /**
     * Include default settings in response
     * @param includeDefaults Whether to include default settings
     */
    GetSettingsRequest includeDefaults(boolean includeDefaults);
    
    /**
     * Get target indices
     */
    String[] indices();
    
    /**
     * Get setting names to retrieve
     */
    String[] names();
}

/**
 * Response containing index settings information
 */
class GetSettingsResponse extends ActionResponse {
    /**
     * Get settings for specific index
     * @param index Index name
     */
    Settings getIndexSettings(String index);
    
    /**
     * Get all index settings as map
     */
    Map<String, Settings> getIndexToSettings();
    
    /**
     * Get setting value for specific index and setting name
     * @param index Index name
     * @param setting Setting name
     */
    String getSetting(String index, String setting);
}

Mapping Management

APIs for defining and managing field mappings and document structure.

/**
 * Request to put or update index mapping definitions
 */
class PutMappingRequest extends ActionRequest {
    /**
     * Create put mapping request for specified indices
     * @param indices Index names to apply mapping to
     */
    PutMappingRequest(String... indices);
    
    /**
     * Set mapping source from JSON string
     * @param source Mapping definition as JSON
     * @param xContentType Content type of the mapping source
     */
    PutMappingRequest source(String source, XContentType xContentType);
    
    /**
     * Set mapping source from map
     * @param source Mapping definition as key-value pairs
     */
    PutMappingRequest source(Map<String, Object> source);
    
    /**
     * Set request timeout
     * @param timeout Operation timeout
     */
    PutMappingRequest timeout(String timeout);
    
    /**
     * Set cluster manager node timeout
     * @param clusterManagerNodeTimeout Timeout for cluster manager operations
     */
    PutMappingRequest clusterManagerNodeTimeout(String clusterManagerNodeTimeout);
    
    /**
     * Get target indices
     */
    String[] indices();
    
    /**
     * Get mapping source
     */
    String source();
}

/**
 * Request to retrieve index mapping definitions
 */
class GetMappingsRequest extends ActionRequest {
    /**
     * Create get mappings request for specified indices
     * @param indices Index names to get mappings for
     */
    GetMappingsRequest(String... indices);
    
    /**
     * Set local flag for cluster state retrieval
     * @param local Whether to retrieve from local cluster state
     */
    GetMappingsRequest local(boolean local);
    
    /**
     * Get target indices
     */
    String[] indices();
}

/**
 * Response containing index mapping definitions
 */
class GetMappingsResponse extends ActionResponse {
    /**
     * Get all mappings as map
     */
    Map<String, MappingMetadata> mappings();
    
    /**
     * Get mapping for specific index
     * @param index Index name
     */
    MappingMetadata getMappings(String index);
}

/**
 * Mapping metadata container for field definitions and properties
 */
class MappingMetadata implements Streamable {
    /**
     * Get mapping type (usually "_doc")
     */
    String type();
    
    /**
     * Get mapping source as map
     */
    Map<String, Object> sourceAsMap();
    
    /**
     * Get mapping source as string
     */
    String source();
    
    /**
     * Get routing configuration
     */
    Routing routing();
}

Index Operations

Lifecycle operations for managing index state and maintenance.

/**
 * Request to open closed indices
 */
class OpenIndexRequest extends ActionRequest {
    /**
     * Create open index request for specified indices
     * @param indices Index names to open
     */
    OpenIndexRequest(String... indices);
    
    /**
     * Set request timeout
     * @param timeout Operation timeout
     */
    OpenIndexRequest timeout(String timeout);
    
    /**
     * Set cluster manager node timeout
     * @param clusterManagerNodeTimeout Timeout for cluster manager operations
     */
    OpenIndexRequest clusterManagerNodeTimeout(String clusterManagerNodeTimeout);
    
    /**
     * Wait for active shards before returning
     * @param waitForActiveShards Number of active shards to wait for
     */
    OpenIndexRequest waitForActiveShards(ActiveShardCount waitForActiveShards);
    
    /**
     * Get target indices
     */
    String[] indices();
}

/**
 * Request to close open indices
 */
class CloseIndexRequest extends ActionRequest {
    /**
     * Create close index request for specified indices
     * @param indices Index names to close
     */
    CloseIndexRequest(String... indices);
    
    /**
     * Set request timeout
     * @param timeout Operation timeout
     */
    CloseIndexRequest timeout(String timeout);
    
    /**
     * Set cluster manager node timeout  
     * @param clusterManagerNodeTimeout Timeout for cluster manager operations
     */
    CloseIndexRequest clusterManagerNodeTimeout(String clusterManagerNodeTimeout);
    
    /**
     * Get target indices
     */
    String[] indices();
}

/**
 * Request to refresh indices and make recent changes searchable
 */
class RefreshRequest extends ActionRequest {
    /**
     * Create refresh request for specified indices
     * @param indices Index names to refresh (empty for all)
     */
    RefreshRequest(String... indices);
    
    /**
     * Get target indices
     */
    String[] indices();
}

/**
 * Response for refresh operations
 */
class RefreshResponse extends ActionResponse {
    /**
     * Get total number of shards
     */
    int getTotalShards();
    
    /**
     * Get number of successful shards
     */
    int getSuccessfulShards();
    
    /**
     * Get number of failed shards
     */
    int getFailedShards();
    
    /**
     * Get shard failures if any
     */
    DefaultShardOperationFailedException[] getShardFailures();
}

/**
 * Request to flush indices and commit changes to storage
 */
class FlushRequest extends ActionRequest {
    /**
     * Create flush request for specified indices
     * @param indices Index names to flush (empty for all)
     */
    FlushRequest(String... indices);
    
    /**
     * Set whether to wait for ongoing operations
     * @param waitIfOngoing Whether to wait for ongoing operations to complete
     */
    FlushRequest waitIfOngoing(boolean waitIfOngoing);
    
    /**
     * Force flush even if not necessary
     * @param force Whether to force flush
     */
    FlushRequest force(boolean force);
    
    /**
     * Get target indices
     */
    String[] indices();
}

/**
 * Request to force merge index segments for optimization
 */
class ForceMergeRequest extends ActionRequest {
    /**
     * Create force merge request for specified indices
     * @param indices Index names to force merge (empty for all)
     */
    ForceMergeRequest(String... indices);
    
    /**
     * Set maximum number of segments to merge down to
     * @param maxNumSegments Target number of segments per shard
     */
    ForceMergeRequest maxNumSegments(int maxNumSegments);
    
    /**
     * Set whether to only expunge deleted documents
     * @param onlyExpungeDeletes Whether to only expunge deletes
     */
    ForceMergeRequest onlyExpungeDeletes(boolean onlyExpungeDeletes);
    
    /**
     * Set whether to flush after merge
     * @param flush Whether to flush after merge
     */
    ForceMergeRequest flush(boolean flush);
    
    /**
     * Get target indices
     */
    String[] indices();
}

Index Aliases

APIs for managing index aliases and multi-index operations.

/**
 * Index alias configuration for alternative index names
 */
class Alias implements Streamable {
    /**
     * Create alias with specified name
     * @param name Alias name
     */
    Alias(String name);
    
    /**
     * Set routing value for alias operations
     * @param routing Routing value for shard selection
     */
    Alias routing(String routing);
    
    /**
     * Set search routing value
     * @param searchRouting Routing value for search operations
     */
    Alias searchRouting(String searchRouting);
    
    /**
     * Set index routing value
     * @param indexRouting Routing value for index operations
     */
    Alias indexRouting(String indexRouting);
    
    /**
     * Set filter query for alias
     * @param filter Filter query to apply to alias operations
     */
    Alias filter(QueryBuilder filter);
    
    /**
     * Get alias name
     */
    String name();
    
    /**
     * Get routing configuration
     */
    String routing();
}

/**
 * Request to manage index aliases (add, remove, modify)
 */
class IndicesAliasesRequest extends ActionRequest {
    /**
     * Create indices aliases request
     */
    IndicesAliasesRequest();
    
    /**
     * Add alias action to request
     * @param aliasAction Action to perform (add, remove, remove_index)
     */
    IndicesAliasesRequest addAliasAction(AliasActions aliasAction);
    
    /**
     * Set request timeout
     * @param timeout Operation timeout
     */
    IndicesAliasesRequest timeout(String timeout);
    
    /**
     * Get list of alias actions
     */
    List<AliasActions> getAliasActions();
    
    /**
     * Individual alias action (add, remove, remove_index)
     */
    abstract static class AliasActions implements Streamable {
        /**
         * Create add alias action
         */
        static AliasActions add();
        
        /**
         * Create remove alias action
         */
        static AliasActions remove();
        
        /**
         * Create remove index action
         */
        static AliasActions removeIndex();
        
        /**
         * Set target indices
         * @param indices Index names
         */
        AliasActions indices(String... indices);
        
        /**
         * Set alias name
         * @param alias Alias name
         */
        AliasActions alias(String alias);
        
        /**
         * Set routing value
         * @param routing Routing value
         */
        AliasActions routing(String routing);
        
        /**
         * Set filter query
         * @param filter Filter query
         */
        AliasActions filter(QueryBuilder filter);
    }
}

Usage Examples

Creating Indices with Settings and Mappings

import org.opensearch.action.admin.indices.create.CreateIndexRequest;
import org.opensearch.action.admin.indices.create.CreateIndexResponse;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentType;

// Create index with custom settings
CreateIndexRequest request = new CreateIndexRequest("products");

// Configure index settings
Settings settings = Settings.builder()
    .put("index.number_of_shards", 3)
    .put("index.number_of_replicas", 1)
    .put("index.refresh_interval", "1s")
    .put("analysis.analyzer.custom_analyzer.type", "custom")
    .put("analysis.analyzer.custom_analyzer.tokenizer", "standard")
    .put("analysis.analyzer.custom_analyzer.filter", new String[]{"lowercase", "stop"})
    .build();

request.settings(settings);

// Define field mappings
String mapping = """
    {
        "properties": {
            "name": {
                "type": "text",
                "analyzer": "custom_analyzer"
            },
            "description": {
                "type": "text",
                "analyzer": "standard"
            },
            "price": {
                "type": "double"
            },
            "category": {
                "type": "keyword"
            },
            "created_date": {
                "type": "date",
                "format": "yyyy-MM-dd HH:mm:ss"
            },
            "tags": {
                "type": "keyword"
            },
            "location": {
                "type": "geo_point"
            }
        }
    }
    """;

request.mapping(mapping, XContentType.JSON);

// Add index alias
request.alias(new Alias("products_current"));

CreateIndexResponse response = client.admin().indices().create(request);
System.out.println("Index created: " + response.isAcknowledged());

Updating Index Settings

import org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest;
import org.opensearch.action.support.master.AcknowledgedResponse;

// Update dynamic settings for existing index
UpdateSettingsRequest updateRequest = new UpdateSettingsRequest("products");

Settings updatedSettings = Settings.builder()
    .put("index.refresh_interval", "5s")
    .put("index.max_result_window", 20000)
    .put("index.number_of_replicas", 2)
    .build();

updateRequest.settings(updatedSettings);

AcknowledgedResponse updateResponse = client.admin().indices().updateSettings(updateRequest);
System.out.println("Settings updated: " + updateResponse.isAcknowledged());

Managing Index Mappings

import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest;
import org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse;

// Add new fields to existing mapping
PutMappingRequest putMappingRequest = new PutMappingRequest("products");

String newMapping = """
    {
        "properties": {
            "rating": {
                "type": "float"
            },
            "reviews": {
                "type": "nested",
                "properties": {
                    "user": {"type": "keyword"},
                    "comment": {"type": "text"},
                    "score": {"type": "integer"}
                }
            }
        }
    }
    """;

putMappingRequest.source(newMapping, XContentType.JSON);

AcknowledgedResponse putMappingResponse = client.admin().indices().putMapping(putMappingRequest);
System.out.println("Mapping updated: " + putMappingResponse.isAcknowledged());

// Retrieve current mappings
GetMappingsRequest getMappingsRequest = new GetMappingsRequest("products");
GetMappingsResponse getMappingsResponse = client.admin().indices().getMappings(getMappingsRequest);

MappingMetadata mappingMetadata = getMappingsResponse.getMappings().get("products");
System.out.println("Current mapping: " + mappingMetadata.source());

Index Lifecycle Operations

import org.opensearch.action.admin.indices.close.CloseIndexRequest;
import org.opensearch.action.admin.indices.open.OpenIndexRequest;
import org.opensearch.action.admin.indices.refresh.RefreshRequest;
import org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest;

// Close index to save resources
CloseIndexRequest closeRequest = new CloseIndexRequest("old_products");
AcknowledgedResponse closeResponse = client.admin().indices().close(closeRequest);
System.out.println("Index closed: " + closeResponse.isAcknowledged());

// Reopen index when needed
OpenIndexRequest openRequest = new OpenIndexRequest("old_products");
AcknowledgedResponse openResponse = client.admin().indices().open(openRequest);
System.out.println("Index opened: " + openResponse.isAcknowledged());

// Refresh index to make recent changes searchable
RefreshRequest refreshRequest = new RefreshRequest("products");
RefreshResponse refreshResponse = client.admin().indices().refresh(refreshRequest);
System.out.println("Refresh successful shards: " + refreshResponse.getSuccessfulShards());

// Force merge to optimize storage
ForceMergeRequest forceMergeRequest = new ForceMergeRequest("products");
forceMergeRequest.maxNumSegments(1); // Merge to single segment per shard
forceMergeRequest.onlyExpungeDeletes(false);
forceMergeRequest.flush(true);

ForceMergeResponse forceMergeResponse = client.admin().indices().forceMerge(forceMergeRequest);
System.out.println("Force merge completed");

Managing Index Aliases

import org.opensearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.opensearch.action.admin.indices.alias.get.GetAliasesRequest;
import org.opensearch.index.query.QueryBuilders;

// Create alias management request
IndicesAliasesRequest aliasRequest = new IndicesAliasesRequest();

// Add new alias with filter
aliasRequest.addAliasAction(
    IndicesAliasesRequest.AliasActions.add()
        .indices("products_2024_*")
        .alias("products_current")
        .filter(QueryBuilders.termQuery("status", "active"))
);

// Remove old alias
aliasRequest.addAliasAction(
    IndicesAliasesRequest.AliasActions.remove()
        .indices("products_2023_*")
        .alias("products_current")
);

// Add routing alias
aliasRequest.addAliasAction(
    IndicesAliasesRequest.AliasActions.add()
        .indices("products_2024_01")
        .alias("products_jan")
        .routing("jan")
);

AcknowledgedResponse aliasResponse = client.admin().indices().updateAliases(aliasRequest);
System.out.println("Aliases updated: " + aliasResponse.isAcknowledged());

Types

/**
 * Index metadata container with settings, mappings, and aliases
 */
class IndexMetadata implements Streamable {
    /**
     * Get index name
     */
    String getIndex();
    
    /**
     * Get index UUID
     */
    String getIndexUUID();
    
    /**
     * Get index settings
     */
    Settings getSettings();
    
    /**
     * Get index mappings
     */
    Map<String, MappingMetadata> getMappings();
    
    /**
     * Get index aliases
     */
    Map<String, AliasMetadata> getAliases();
    
    /**
     * Get index state
     */
    State getState();
    
    /**
     * Index state enumeration
     */
    enum State {
        OPEN, CLOSE
    }
}

/**
 * Alias metadata containing alias configuration
 */
class AliasMetadata implements Streamable {
    /**
     * Get alias name
     */
    String alias();
    
    /**
     * Get filter query
     */
    CompressedXContent filter();
    
    /**
     * Get index routing
     */
    String indexRouting();
    
    /**
     * Get search routing
     */
    String searchRouting();
}

/**
 * Active shard count configuration for index operations
 */
class ActiveShardCount implements Streamable {
    /**
     * Wait for all shards to be active
     */
    static final ActiveShardCount ALL;
    
    /**
     * Don't wait for any shards
     */
    static final ActiveShardCount NONE;
    
    /**
     * Wait for default number of shards (1)
     */
    static final ActiveShardCount DEFAULT;
    
    /**
     * Create active shard count for specific number
     * @param count Number of shards to wait for
     */
    static ActiveShardCount from(int count);
}

/**
 * Content type enumeration for request bodies
 */
enum XContentType {
    /**
     * JavaScript Object Notation
     */
    JSON,
    
    /**
     * YAML Ain't Markup Language
     */
    YAML,
    
    /**
     * Concise Binary Object Representation
     */
    CBOR,
    
    /**
     * Extensible Markup Language
     */
    XML
}

Install with Tessl CLI

npx tessl i tessl/maven-org-opensearch--opensearch

docs

action-framework.md

client-apis.md

cluster-management.md

index-management.md

index.md

plugin-framework.md

search-apis.md

tile.json