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

Remove unsupported fields from PutMappingRequest #597

Merged
merged 1 commit into from
Aug 21, 2023

Conversation

VachaShah
Copy link
Collaborator

Description

Finishing up PR #288

Issues Resolved

Closes #62

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

dblock
dblock previously approved these changes Aug 9, 2023
@VachaShah
Copy link
Collaborator Author

Fixed the merge conflicts

@VachaShah VachaShah requested a review from dblock August 15, 2023 18:30
private final Boolean dateDetection;

@Nullable
private final DynamicMapping dynamic;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VachaShah my apologies but I think we are removing the fields that are indeed supported and are valid, for example:

        PutMappingRequest.Builder mappingsRequestBuilder = new PutMappingRequest.Builder().index("index")
            .source(
                new SourceField.Builder()
                    .enabled(true)
                    .build())
            .routing(
                new RoutingField.Builder()
                    .required(true)
                    .build())
            .dynamic(DynamicMapping.Strict);

        client.indices().putMapping(mappingsRequestBuilder.build());

Gives me perfectly updated index mappings:

{
  "index" : {
    "aliases" : { },
    "mappings" : {
      "dynamic" : "strict",
      "_routing" : {
        "required" : true
      }
    },
    "settings" : {
      "index" : {
        "replication" : {
          "type" : "DOCUMENT"
        },
        "number_of_shards" : "1",
        "provided_name" : "index",
        "creation_date" : "1692189016042",
        "number_of_replicas" : "1",
        "uuid" : "_5OAxCkmQZOzhWkEsyub3g",
        "version" : {
          "created" : "137217827"
        }
      }
    }
  }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my bad! Thank you @reta for pointing out. Let me test this out and see if any other fields are supported as well. I will update the PR with the changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reta I tried all the fields and all fields work except runtime. Sample code:

PutMappingRequest.Builder mappingsRequestBuilder = new PutMappingRequest.Builder().index("index")
            .source(
                new SourceField.Builder()
                    .enabled(true)
                    .build())
            .routing(
                new RoutingField.Builder()
                    .required(false)
                    .build())
            .dynamic(DynamicMapping.Strict)
            .meta("key", JsonData.of("key value"))
            .fieldNames(new FieldNamesField.Builder().enabled(false).build())
            .dateDetection(false)
            .dynamicDateFormats(new ArrayList<>())
            .dynamicTemplates(new ArrayList<>())
            .numericDetection(false)
            .runtime("runtime", new RuntimeField.Builder().type(RuntimeFieldType.Boolean).build());
client.indices().putMapping(mappingsRequestBuilder.build());

To which I got the below error:

Mapping response: org.opensearch.client.opensearch.indices.get_mapping.IndexMappingRecord@44040454
Exception in thread "main" org.opensearch.client.opensearch._types.OpenSearchException: Request failed: [mapper_parsing_exception] Root mapping definition has unsupported parameters:  [runtime : {runtime={type=boolean}}]
        at org.opensearch.client.transport.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:278)
        at org.opensearch.client.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:144)
        at org.opensearch.client.opensearch.indices.OpenSearchIndicesClient.putMapping(OpenSearchIndicesClient.java:1148)
        at hello.OpenSearchValidateClient.main(OpenSearchValidateClient.java:234)

I think I am using runtime parameter correctly but LMK if thats not the case.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @VachaShah !

I think I am using runtime parameter correctly but LMK if thats not the case.

Correct, we don't support runtime fields (this is ES only feature)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay! I will update this PR accordingly. Thank you :)

Signed-off-by: Vacha Shah <vachshah@amazon.com>
@dblock
Copy link
Member

dblock commented Aug 21, 2023

I think a good practice we could start following to catch bugs like the one @reta pointed out in the CR is to start adding working samples to https://github.com/opensearch-project/opensearch-java/tree/main/samples as part of these changes. Just an idea!

@dblock dblock merged commit d80f015 into opensearch-project:main Aug 21, 2023
29 checks passed
@VachaShah
Copy link
Collaborator Author

I think a good practice we could start following to catch bugs like the one @reta pointed out in the CR is to start adding working samples to https://github.com/opensearch-project/opensearch-java/tree/main/samples as part of these changes. Just an idea!

Yup that makes sense! I have a working sample with which I tested. I will add it in an upcoming PR.

@VachaShah VachaShah deleted the issue-62 branch August 21, 2023 21:05
@VachaShah VachaShah added the backport 2.x Backport to 2.x branch label Aug 21, 2023
@opensearch-trigger-bot
Copy link

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-597-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 d80f0151ca418d6a7bc63d2c616a88ba98d3c472
# Push it to GitHub
git push --set-upstream origin backport/backport-597-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-597-to-2.x.

VachaShah added a commit to VachaShah/opensearch-java that referenced this pull request Aug 22, 2023
VachaShah added a commit that referenced this pull request Aug 22, 2023
Signed-off-by: Vacha Shah <vachshah@amazon.com>
@BrendonFaleiro BrendonFaleiro mentioned this pull request Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Bad request response when calling the PutMapping api
3 participants