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 unmatch_mapping_type, and support array of types #103171

Merged

Conversation

axw
Copy link
Member

@axw axw commented Dec 8, 2023

Add an unmatch_mapping_type condition to dynamic templates (supporting one or more types), and add support for specifying a list of types to match_mapping_type.

Closes #102795
Closes #102807

Add an unmatch_mapping_type condition to dynamic templates,
and add support for specifying a list of types to
match_mapping_type.
@elasticsearchmachine elasticsearchmachine added external-contributor Pull request authored by a developer outside the Elasticsearch team v8.13.0 labels Dec 8, 2023
@axw
Copy link
Member Author

axw commented Dec 8, 2023

@felixbarny @javanna I took a stab at addressing the linked issues. Could you please tell me if this looks directionally sensible, and if you can spot any major issues? If it looks alright I'll proceed to add docs and probably expand the tests a bit.

The main thing I'm unsure about is backwards compatibility with respect to the serialisation changes. Do we need to do something special for cluster upgrades?

@felixbarny
Copy link
Member

A good template for this change would be this PR:

The main thing I'm unsure about is backwards compatibility with respect to the serialisation changes. Do we need to do something special for cluster upgrades?

Seems like that PR doesn't do anything special here with regards to the serialization changes. However, I think there may be a problematic situation that can occur in this code line in a mixed version cluster scenario (such as when doing a rolling upgrade):

final XContentFieldType xContentFieldType = XContentFieldType.fromString(matchMappingType);

If one node in a cluster gets updated and the user sends a mapping update request to that node, it may propagate that mapping to older nodes that expect the content of match_mapping_type to be a string and they'd fail when an array of values is passed.

But maybe all of that is a non issue, depending on how the update process works. IIRC, at first, all non-master nodes are updated before the master node. Also, updating the mapping would go though the master node that triggers a cluster state update to propagate the mappings to other nodes. During that process, the master node would validate the mappings. I think that makes sure that ES will only accept mappings with an array in match_mapping_type when all nodes in the cluster are updated.

axw and others added 5 commits December 9, 2023 08:23
…plate.java

Co-authored-by: Felix Barnsteiner <felixbarny@users.noreply.github.com>
- Use addEntriesToPatternList like match/path_match etc.
- Serialise (un)match_mapping_type as specified, except
  for single-value lists which are always serialised as
  a non-list value. Implicit "match_mapping_type: *" is
  still not serialised, but an explicit setting will now
  be serialised where it was not before.
... to highlight the original purpose, which is to
unmatch an internal object field whose path may match
a leaf field.
@axw
Copy link
Member Author

axw commented Dec 11, 2023

@elasticmachine run elasticsearch-ci/packaging-tests-windows-sample

@felixbarny felixbarny added >feature :Search/Mapping Index mappings, including merging and defining field types labels Dec 11, 2023
@elasticsearchmachine
Copy link
Collaborator

Hi @axw, I've created a changelog YAML for you.

Copy link
Member

@felixbarny felixbarny left a comment

Choose a reason for hiding this comment

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

Just a minor suggestion, otherwise LGTM. This also needs to be reviewed by the search team before merging.

Move runtime-supported type filtering.
@axw axw marked this pull request as ready for review December 12, 2023 07:59
@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Dec 12, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@axw
Copy link
Member Author

axw commented Jan 25, 2024

@salvatore-campagna would you be able to review this PR? Or otherwise tag someone else more appropriate? 🙏

@siposea siposea added the :StorageEngine/Logs You know, for Logs label Jan 25, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

@@ -257,7 +260,8 @@ static DynamicTemplate parse(String name, Map<String, Object> conf) throws Mappe
List<String> pathUnmatch = new ArrayList<>(4);
Map<String, Object> mapping = null;
boolean runtime = false;
String matchMappingType = null;
List<String> matchMappingType = new ArrayList<>(4);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the size of the array 4? Just to have a size that is lower than he default?

Copy link
Member

Choose a reason for hiding this comment

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

This uses the same initial size of the array list as the other lists a few lines above. I think this is because we expect most of these to have one or a few values, so a custom default value 4 aims for more efficiency than the generic default value.

builder.field("unmatch_mapping_type", unmatchMappingType.get(0));
} else {
builder.field("unmatch_mapping_type", unmatchMappingType);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Logic seems similar...maybe extract a method just passing a list and a string?

Copy link
Member

Choose a reason for hiding this comment

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

let me add that

@salvatore-campagna
Copy link
Contributor

LGTM, I left a question and a comment.

@felixbarny felixbarny added the auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Feb 9, 2024
@elasticsearchmachine elasticsearchmachine merged commit 5f90978 into elastic:main Feb 9, 2024
15 checks passed
@axw axw deleted the dynamic-template-unmatch-mapping-type branch February 9, 2024 15:42
martijnvg pushed a commit to martijnvg/elasticsearch that referenced this pull request Feb 12, 2024
Add an `unmatch_mapping_type` condition to dynamic templates (supporting
one or more types), and add support for specifying a list of types to
`match_mapping_type`.

Closes elastic#102795 Closes
elastic#102807
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) external-contributor Pull request authored by a developer outside the Elasticsearch team >feature :Search/Mapping Index mappings, including merging and defining field types :StorageEngine/Logs You know, for Logs Team:Search Meta label for search team Team:StorageEngine v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a way to set array of types in match_mapping_type Add unmatch_mapping_type dynamic template condition
5 participants