Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] settings.index.knn.algo_param.ef_search skipped during deserialization #1414

Open
joshjluo opened this issue Feb 6, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@joshjluo
Copy link

joshjluo commented Feb 6, 2025

What is the bug?

A clear and concise description of the bug.

The settings.index.knn.algo_param.ef_search field does not appear to be deserialized correctly.

How can one reproduce the bug?

Steps to reproduce the behavior.

  1. Create an index with settings.index.knn.algo_param.ef_search
CreateIndexRequest.Builder createIndexRequestBuilder = new CreateIndexRequest.Builder().index("bug-repro-index");
IndexSettings.Builder indexSettingsBuilder = new IndexSettings.Builder();
indexSettingsBuilder.knn(true);
indexSettingsBuilder.knnAlgoParamEfSearch(512);
CreateIndexResponse createIndexResponse = client.indices().create(createIndexRequestBuilder.settings(indexSettingsBuilder.build()).build());
  1. Get the index
GetIndexRequest getIndexRequest = new GetIndexRequest.Builder().index("bug-repro-index").build();
GetIndexResponse getIndexResponse = client.indices().get(getIndexRequest);
if (getIndexResponse.result().get("bug-repro-index").settings().index().knnAlgoParamEfSearch() == null) {
    System.out.println("This is a bug");
}
  1. See that the field is null

What is the expected behavior?

A clear and concise description of what you expected to happen.

The settings.index.knn.algo_param.ef_search field should be not null and should be set to the expected value of 512 in the example.

What is your host/environment?

Operating system, version.

Do you have any screenshots?

If applicable, add screenshots to help explain your problem.

N/A

Do you have any additional context?

Add any other context about the problem.

When examining the response from GET /bug-repro-index from the OpenSearch Dashboard, it is shaped like

{
  "bug-repro-index": {
    "aliases": {},
    "mappings": {},
    "settings": {
      "index": {
        "number_of_shards": "2",
        "knn": {
          "algo_param": {
            "ef_search": "512"
          }
        },
        "provided_name": "bug-repro-index",
        "knn": "true",
        "creation_date": "1738883254271",
        "number_of_replicas": "0",
        "uuid": "K2qJ1UPLcQdi9m5AxzXr",
        "version": {
          "created": "136327827"
        }
      }
    }
  }
}

Notice that the response has settings.index.knn.algo_param.ef_search as a nested object rather than a flattened field. After debugging and stepping through the code, seems like there are a few contributing issues:

  1. There is a map of field names to deserializers (see code). When the response is being deserialized, the field name is knn.algo_param. However, the map does not contain knn.algo_param - it only contains knn.algo_param.ef_search and index.knn.algo_param.ef_search. Because this field name is not recognized, it gets skipped (see code).
  2. It seems like the generated code is expecting an integer for deserialization. However, I'd expect it to use a deserializer for an object, similar to the settings.index.version field (see generated code).

Minimal Java class used for testing

package org.example;

import org.opensearch.client.opensearch.OpenSearchClient;
import org.opensearch.client.opensearch.indices.CreateIndexRequest;
import org.opensearch.client.opensearch.indices.CreateIndexResponse;
import org.opensearch.client.opensearch.indices.GetIndexRequest;
import org.opensearch.client.opensearch.indices.GetIndexResponse;
import org.opensearch.client.opensearch.indices.IndexSettings;
import org.opensearch.client.transport.aws.AwsSdk2Transport;
import org.opensearch.client.transport.aws.AwsSdk2TransportOptions;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.http.SdkHttpClient;
import software.amazon.awssdk.http.apache.ApacheHttpClient;
import software.amazon.awssdk.regions.Region;

import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        SdkHttpClient httpClient = ApacheHttpClient.builder().build();
        AwsCredentialsProvider provider = DefaultCredentialsProvider.create();

        OpenSearchClient client = new OpenSearchClient(
            new AwsSdk2Transport(
                httpClient,
                "collectionid.us-east-1.aoss.amazonaws.com", // OpenSearch endpoint, without https://
                "aoss",
                Region.US_EAST_1,
                AwsSdk2TransportOptions.builder().setCredentials(provider).build()
            )
        );

        CreateIndexRequest.Builder createIndexRequestBuilder = new CreateIndexRequest.Builder().index("bug-repro-index");
        IndexSettings.Builder indexSettingsBuilder = new IndexSettings.Builder();
        indexSettingsBuilder.knn(true);
        indexSettingsBuilder.knnAlgoParamEfSearch(512);
        CreateIndexResponse createIndexResponse = client.indices().create(
            createIndexRequestBuilder.settings(indexSettingsBuilder.build()).build());


        GetIndexRequest getIndexRequest = new GetIndexRequest.Builder().index("bug-repro-index").build();
        GetIndexResponse getIndexResponse = client.indices().get(getIndexRequest);
        if (getIndexResponse.result().get("bug-repro-index").settings().index().knnAlgoParamEfSearch() == null) {
            System.out.println("This is a bug");
        }

        httpClient.close();
    }
}
@joshjluo joshjluo added bug Something isn't working untriaged labels Feb 6, 2025
@Xtansia Xtansia removed the untriaged label Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants