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

Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue #2759

Merged
merged 4 commits into from
Jul 26, 2024

Conversation

rbhavna
Copy link
Collaborator

@rbhavna rbhavna commented Jul 26, 2024

Description

Adds the _doc key wrapper around index mapping as required by CreateIndexRequest javadoc.

Related Issues

See also opensearch-project/OpenSearch#14984

Testing Details

When the cluster has v1 templates with patterns matching the index, without the _doc wrapper, dynamic mappings are getting enabled for the index. From below, created_time is being created as long (dynamically picked) instead of timestamp type which is defined in the mapping definition.

Screenshot 2024-07-26 at 1 54 05 PM

With changes in this PR by adding _doc wrapper, even if cluster has v1 templates, indices are getting created with expected mappings.

Screenshot 2024-07-26 at 2 17 26 PM

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

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.

Zhangxunmt
Zhangxunmt previously approved these changes Jul 26, 2024
@rbhavna rbhavna temporarily deployed to ml-commons-cicd-env July 26, 2024 18:40 — with GitHub Actions Inactive
@ylwu-amzn
Copy link
Collaborator

Have you checked any difference by wrapping index mapping with _doc or not ?

Signed-off-by: Bhavana Ramaram <[email protected]>
@dbwiddis
Copy link
Member

@rbhavna please unlink the opensearch bug as there are other impacted plugins that need to track it

@rbhavna
Copy link
Collaborator Author

rbhavna commented Jul 26, 2024

Have you checked any difference by wrapping index mapping with _doc or not ?

Yes when v1 template is added already, without _doc wrapper I see dynamic mappings are created. Will add details to PR description

@dbwiddis
Copy link
Member

dbwiddis commented Jul 26, 2024

Have you checked any difference by wrapping index mapping with _doc or not ?

@ylwu-amzn I've tested all combinations (with and without _doc) and with/without v1 and v2 templates. The only failure occurs with the v1 template and lack of _doc. Adding _doc does not cause any additional problems and is, in fact, added by the REST API.

@owaiskazi19 and I walked through all code paths with both deprecated v1 and current v2 mappings. In v2 case and with no v1 mapping, code automatically determines the _doc type at run time and thus these not impacted as they are processed in a list. The only impact is with v1 (deprecated) index templates which do a map "merge" and because the template populates the _doc field, it is now "present" and the auto-populating that occurs when there's no _doc doesn't happen and the user mapping is lost.

@owaiskazi19
Copy link
Member

owaiskazi19 commented Jul 26, 2024

@rbhavna just to be sure, can you also test with v2 templates both the scenario?
Also, looks like you attached the same screenshot in the description

@@ -87,7 +87,7 @@ public void initConversationMetaIndexIfAbsent(ActionListener<Boolean> listener)
log.debug("No conversational meta index found. Adding it");
CreateIndexRequest request = Requests
.createIndexRequest(META_INDEX_NAME)
.mapping(ConversationalIndexConstants.META_MAPPING)
.mapping("{\"_doc\":" + ConversationalIndexConstants.META_MAPPING + "}")
Copy link
Member

@dbwiddis dbwiddis Jul 26, 2024

Choose a reason for hiding this comment

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

FYI after further research, another possible (and less controversial) fix is using a differnet method that includes the MediaType, which auto-adds the doc field internally. This format is also used elsewhere.

Suggested change
.mapping("{\"_doc\":" + ConversationalIndexConstants.META_MAPPING + "}")
.mapping(ConversationalIndexConstants.META_MAPPING, XContentType.JSON)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@rbhavna
Copy link
Collaborator Author

rbhavna commented Jul 26, 2024

@rbhavna just to be sure, can you also test with v2 templates both the scenario? Also, looks like you attached the same screenshot in the description

Thanks @owaiskazi19 Updated the description. And will do more testing with v2 templates

@rbhavna
Copy link
Collaborator Author

rbhavna commented Jul 26, 2024

Have you checked any difference by wrapping index mapping with _doc or not ?

@ylwu-amzn I've tested all combinations (with and without _doc) and with/without v1 and v2 templates. The only failure occurs with the v1 template and lack of _doc. Adding _doc does not cause any additional problems and is, in fact, added by the REST API.

@owaiskazi19 and I walked through all code paths with both deprecated v1 and current v2 mappings. In v2 case and with no v1 mapping, code automatically determines the _doc type at run time and thus these not impacted as they are processed in a list. The only impact is with v1 (deprecated) index templates which do a map "merge" and because the template populates the _doc field, it is now "present" and the auto-populating that occurs when there's no _doc doesn't happen and the user mapping is lost.

I am actually curious if we can have similar fix for update index as well. This fix will take care of any newly created domains from 2.15. For domains upgrading from previous versions with incorrect mappings to 2.15, do you think adding this _doc wrapper helps?

@rbhavna rbhavna temporarily deployed to ml-commons-cicd-env July 26, 2024 21:44 — with GitHub Actions Inactive
@rbhavna rbhavna temporarily deployed to ml-commons-cicd-env July 26, 2024 22:14 — with GitHub Actions Inactive
@rbhavna rbhavna changed the title Wrap CreateIndexRequest mappings in _doc key in ml-commons Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue Jul 26, 2024
@rbhavna rbhavna merged commit 1c43be5 into opensearch-project:main Jul 26, 2024
9 of 10 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jul 26, 2024
…to fix v1 templates issue (#2759)

* Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue

Signed-off-by: Bhavana Ramaram <[email protected]>
(cherry picked from commit 1c43be5)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jul 26, 2024
…to fix v1 templates issue (#2759)

* Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue

Signed-off-by: Bhavana Ramaram <[email protected]>
(cherry picked from commit 1c43be5)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jul 26, 2024
…to fix v1 templates issue (#2759)

* Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue

Signed-off-by: Bhavana Ramaram <[email protected]>
(cherry picked from commit 1c43be5)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jul 26, 2024
…to fix v1 templates issue (#2759)

* Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue

Signed-off-by: Bhavana Ramaram <[email protected]>
(cherry picked from commit 1c43be5)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jul 26, 2024
…to fix v1 templates issue (#2759)

* Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue

Signed-off-by: Bhavana Ramaram <[email protected]>
(cherry picked from commit 1c43be5)
rbhavna added a commit that referenced this pull request Jul 26, 2024
…to fix v1 templates issue (#2759) (#2766)

* Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue

Signed-off-by: Bhavana Ramaram <[email protected]>
(cherry picked from commit 1c43be5)

Co-authored-by: Bhavana Ramaram <[email protected]>
rbhavna added a commit that referenced this pull request Jul 26, 2024
…to fix v1 templates issue (#2759) (#2763)

* Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue

Signed-off-by: Bhavana Ramaram <[email protected]>
(cherry picked from commit 1c43be5)

Co-authored-by: Bhavana Ramaram <[email protected]>
rbhavna added a commit that referenced this pull request Jul 26, 2024
…to fix v1 templates issue (#2759) (#2764)

* Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue

Signed-off-by: Bhavana Ramaram <[email protected]>
(cherry picked from commit 1c43be5)

Co-authored-by: Bhavana Ramaram <[email protected]>
rbhavna added a commit that referenced this pull request Jul 26, 2024
…to fix v1 templates issue (#2759) (#2765)

* Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue

Signed-off-by: Bhavana Ramaram <[email protected]>
(cherry picked from commit 1c43be5)

Co-authored-by: Bhavana Ramaram <[email protected]>
b4sjoo pushed a commit that referenced this pull request Jul 27, 2024
…to fix v1 templates issue (#2759) (#2767)

* Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue

Signed-off-by: Bhavana Ramaram <[email protected]>
(cherry picked from commit 1c43be5)

Co-authored-by: Bhavana Ramaram <[email protected]>
opensearch-trigger-bot bot added a commit that referenced this pull request Oct 2, 2024
…to fix v1 templates issue (#2759) (#2766)

* Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue

Signed-off-by: Bhavana Ramaram <[email protected]>
(cherry picked from commit 1c43be5)

Co-authored-by: Bhavana Ramaram <[email protected]>
(cherry picked from commit 389dd95)
dhrubo-os pushed a commit that referenced this pull request Oct 2, 2024
…to fix v1 templates issue (#2759) (#2766) (#3049)

* Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue

Signed-off-by: Bhavana Ramaram <[email protected]>
(cherry picked from commit 1c43be5)

Co-authored-by: Bhavana Ramaram <[email protected]>
(cherry picked from commit 389dd95)

Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants