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] CreateIndexRequest deserializer is not working as expected #285

Open
owaiskazi19 opened this issue Dec 9, 2022 · 0 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@owaiskazi19
Copy link
Member

owaiskazi19 commented Dec 9, 2022

What is the bug?

Currently, we are deserializing the CreateIndexRequest using the _DESERIALIZER provided by java client

private String getAnomalyDetectorMappings() throws IOException {
        URL url = AnomalyDetectionIndices.class.getClassLoader().getResource(ANOMALY_DETECTORS_INDEX_MAPPING_FILE);
        return Resources.toString(url, Charsets.UTF_8);
    }

JsonpMapper mapper = sdkClient._transport().jsonpMapper();
        JsonParser parser = null;
        try {
            parser = mapper
                .jsonProvider()
                .createParser(new ByteArrayInputStream(getAnomalyDetectorMappings().getBytes(StandardCharsets.UTF_8)));
        } catch (Exception e) {
            e.printStackTrace();
        }

        CreateIndexRequest request = null;
        try {
            request = new CreateIndexRequest.Builder()
                .index(ANOMALY_DETECTORS_INDEX)
                .mappings(TypeMapping._DESERIALIZER.deserialize(parser, mapper))
                .build();
        } catch (Exception e) {
            e.printStackTrace();
        }

This results in adding index response with type object as below:

"featureAttributes": [
                        "com.google.common.collect.SingletonImmutableList",
                        [
                            {
                                "id": "rH6b9YQB_dnlYSXRWwUJ",
                                "name": "test",
                                "enabled": true,
                                "aggregation": {
                                    "@class": "org.opensearch.search.aggregations.metrics.SumAggregationBuilder",
                                    "name": "test",
                                    "metadata": {
                                        "@class": "java.util.Collections$EmptyMap"
                                    },
                                    "type": "sum",
                                    "writeableName": "sum",
                                    "pipelineAggregations": [
                                        "java.util.Collections$UnmodifiableCollection",
                                        []
                                    ],
                                    "subAggregations": [
                                        "java.util.Collections$UnmodifiableCollection",
                                        []
                                    ],
                                    "fragment": true
                                },
                                "fragment": false
                            }
                        ]
                    ],
                    "filterQuery": {
                        "@class": "org.opensearch.index.query.BoolQueryBuilder",
                        "writeableName": "bool",
                        "name": "bool",
                        "fragment": false
                    },
                    "detectionInterval": {
                        "@class": "org.opensearch.ad.model.IntervalTimeConfiguration",
                        "interval": 1,
                        "unit": "MINUTES",
                        "fragment": false
                    },
                    "windowDelay": {
                        "@class": "org.opensearch.ad.model.IntervalTimeConfiguration",
                        "interval": 1,
                        "unit": "MINUTES",
                        "fragment": false
                    },

Adding type object is creating issue while retrieving the index response for GetResponse API for java client.

How can one reproduce the bug?

Steps to reproduce the behavior.

What is the expected behavior?

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

What is your host/environment?

Operating system, version.

Do you have any screenshots?

If applicable, add screenshots to help explain your problem.

Do you have any additional context?

Add any other context about the problem.

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

1 participant