Cannot able to call index search via local host using CURL - 404

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):

3.1.0

Describe the issue:

I am calling the and index search using RestClient like below code

package dev_test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestClient;

import java.util.Base64;
import java.util.Map;

public class TestRestClient {

public static void main(String[] args) {
    String baseUrl = "http://localhost:5601/"; // 🔁 Replace with your base URL

    RestClient restClient = RestClient.builder()
            .baseUrl(baseUrl)
            .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
            .defaultHeader(HttpHeaders.AUTHORIZATION, "Basic "
            + new String(
                Base64.getEncoder()
                    .encode(("admin" + ":" + "Password@123").getBytes())))
            .build();

    Map<String, Object> requestBody = Map.of(
            "size", 100
    );

    try {
        String response = restClient.method(HttpMethod.GET)
        .uri("example_index/_search")
        .body(requestBody)
                .retrieve()
                .body(String.class);

        System.out.println("✅ Response: " + response);
    } catch (Exception e) {
        System.err.println("❌ Error: " + e.getMessage());
    }
}

}

it is throwing

:cross_mark: Error: 404 Not Found: “{“statusCode”:404,“error”:“Not Found”,“message”:“Not Found”}”

But using same restclient if i call findings API

 /_plugins/_security_analytics/findings/_search

I am getting response.

Please any one find or help with issue.

Configuration:

services:
  opensearch-node1: # This is also the hostname of the container within the Docker network (i.e. https://opensearch-node1/)
    image: opensearchproject/opensearch:latest # Specifying the latest available image - modify if you want a specific version
    container_name: opensearch-node1
    environment:
      - cluster.name=opensearch-cluster # Name the cluster
      - node.name=opensearch-node1 # Name the node that will run in this container
      - discovery.seed_hosts=opensearch-node1,opensearch-node2 # Nodes to look for when discovering the cluster
      - cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2 # Nodes eligible to serve as cluster manager
      - bootstrap.memory_lock=true # Disable JVM heap memory swapping
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # Set min and max JVM heap sizes to at least 50% of system RAM
      - OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_INITIAL_ADMIN_PASSWORD}    # Sets the demo admin user password when using demo configuration, required for OpenSearch 2.12 and later
    ulimits:
      memlock:
        soft: -1 # Set memlock to unlimited (no soft or hard limit)
        hard: -1
      nofile:
        soft: 65536 # Maximum number of open files for the opensearch user - set to at least 65536
        hard: 65536
    volumes:
      - opensearch-data1:/usr/share/opensearch/data # Creates volume called opensearch-data1 and mounts it to the container
    ports:
      - 9200:9200 # REST API
      - 9600:9600 # Performance Analyzer
    networks:
      - opensearch-net # All of the containers will join the same Docker bridge network
  opensearch-node2:
    image: opensearchproject/opensearch:latest # This should be the same image used for opensearch-node1 to avoid issues
    container_name: opensearch-node2
    environment:
      - cluster.name=opensearch-cluster
      - node.name=opensearch-node2
      - discovery.seed_hosts=opensearch-node1,opensearch-node2
      - cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2
      - bootstrap.memory_lock=true
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
      - OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_INITIAL_ADMIN_PASSWORD}
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    volumes:
      - opensearch-data2:/usr/share/opensearch/data
    networks:
      - opensearch-net
  opensearch-dashboards:
    image: opensearchproject/opensearch-dashboards:latest # Make sure the version of opensearch-dashboards matches the version of opensearch installed on other nodes
    container_name: opensearch-dashboards
    ports:
      - 5601:5601 # Map host port 5601 to container port 5601
    expose:
      - "5601" # Expose port 5601 for web access to OpenSearch Dashboards
    environment:
      OPENSEARCH_HOSTS: '["https://opensearch-node1:9200","https://opensearch-node2:9200"]' # Define the OpenSearch nodes that OpenSearch Dashboards will query
    networks:
      - opensearch-net

volumes:
  opensearch-data1:
  opensearch-data2:

networks:
  opensearch-net:

Relevant Logs or Screenshots:

@imm31 I think the issue is with the port your script is using:

String baseUrl = "http://localhost:5601/"

In this case you are attempting to issue api request to Opensearch Dashboards, but the api request should be directed to opensearch (on port 9200).

2 Likes

I tried with REST API for port 9200 first i am getting

:cross_mark: Error: I/O error on GET request for http://localhost:9200/test_index/_search: HTTP/1.1 header parser received no bytes.

Docker logs for port:


	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[?:?]

	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:868) ~[?:?]

	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) ~[?:?]

	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:796) ~[?:?]

	at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:697) ~[?:?]

	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:660) ~[?:?]

	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[?:?]

	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:998) ~[?:?]

	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[?:?]

	at java.base/java.lang.Thread.run(Thread.java:1583) [?:?]

Caused by: io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record: 474554202f73656375726974795f646174612f5f73656172636820485454502f312e310d0a436f6e6e656374696f6e3a20557067726164652c2048545450322d53657474696e67730d0a486f73743a206c6f63616c686f73743a393230300d0a48545450322d53657474696e67733a204141454141454141414149414141414241414d414141426b414151424141414141415541414541410d0a557067726164653a206832630d0a557365722d4167656e743a204a6176612d687474702d636c69656e742f32312e302e330d0a417574686f72697a6174696f6e3a20426173696320656d56784f6b6c7964576c74625541794d773d3d0d0a436f6e74656e742d547970653a206170706c69636174696f6e2f6a736f6e0d0a0d0a

	at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1353) ~[?:?]

	at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1428) ~[?:?]

	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:530) ~[?:?]

	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:469) ~[?:?]

	... 16 more

[2025-07-19T06:34:23,110][INFO ][o.o.m.c.MLSyncUpCron     ] [opensearch-node1] Skipping sync up job - ML model index not found

[2025-07-19T06:34:33,115][INFO ][o.o.m.c.MLSyncUpCron     ] [opensearch-node1] Skipping sync up job - ML model index not found
Terminal

But as i mentioned earlier same with findings API call i am getting response

http://localhost:5601/_plugins/_security_analytics/findings/_search

I have found the issue, As mentioned by @Anthony api should point 9200.But OpenSearch often runs with SSL enabled by default. We need to use https://localhost:9200.

Thank you for the support @Anthony