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

Disallow type names to start with dots for new indices except for .percolator #12561

Merged
merged 1 commit into from Aug 12, 2015
Merged

Disallow type names to start with dots for new indices except for .percolator #12561

merged 1 commit into from Aug 12, 2015

Conversation

jasontedor
Copy link
Member

This commit will disallow type names to start with dots except for .percolator for version 2 and later indices.

Closes #12560

@jasontedor jasontedor added >breaking :Search/Mapping Index mappings, including merging and defining field types v2.0.0-beta1 review labels Jul 30, 2015
@jpountz
Copy link
Contributor

jpountz commented Jul 30, 2015

This looks good to me, but I would like @clintongormley to confirm we want this change before merging.

@alexksikes
Copy link
Contributor

This looks good, however we should still allow for plugins to register reserved types?

if (Version.indexCreated(indexSettings).onOrAfter(Version.V_2_0_0_beta1) && typeContainsIllegalDot(mapper)) {
throw new IllegalArgumentException("mapping type name [" + mapper.type() + "] must not contain '.' in it");
}
if (typeContainsIllegalDot(mapper)) {
Copy link
Member

Choose a reason for hiding this comment

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

maybe put this in an if else clause? For me this makes it clearer what is pre 2.0 and what is 2.0 behaviour.

@martijnvg
Copy link
Member

Left one minor comment about the code. I do think we should mention this change in the migrate_2_0.asciidoc file.

@jpountz
Copy link
Contributor

jpountz commented Jul 31, 2015

This looks good, however we should still allow for plugins to register reserved types?

If we think plugins should be able to reserve types, I'd rather not enforce anything in MapperService than make the list of reserved types pluggable. For the record, this would already be an issue today without @jasontedor 's pull request as we are logging a warning for types that contain a dot.

@javanna
Copy link
Member

javanna commented Jul 31, 2015

I think we can replace "reserved type names" in the description of this PR with "percolator type". We don't have a mechanism to register reserved types. The fact that the .percolator type is special is hardcoded, then whether we should open this up to plugins is a different question I think.

I was expecting though any type with name that starts with "." would be hidden, like the .percolator one, but that is not the case, only the .percolator type is treated differently. I wonder whether we should better streamline this "." naming convention or just go with this PR and allow the .percolator only, which is just what we need for now.

@jasontedor jasontedor changed the title Disallow type names to contain dots except for reserved type names for new indices Disallow type names to contain dots for new indices except for .percolator Aug 4, 2015
@jasontedor
Copy link
Member Author

@martijnvg I agree with your suggestion on the code. I squashed a new commit for this that includes updated migration docs as well.

@rjernst
Copy link
Member

rjernst commented Aug 4, 2015

LGTM. Let's go with this PR as is, and revisit reserving type names in plugins later.

@jasontedor
Copy link
Member Author

@clintongormley @jpountz mentioned getting confirmation from you before merging into master.

@clintongormley
Copy link

Hmmm I can see that it could be a good thing to prevent type names from beginning with a dot, but what's the problem with them containing a dot? It used to be a problem when type names were used as a prefix to disambiguate fields, but that syntax is no longer allowed.

Perhaps we should change the restriction to just prevent type names that begin with a dot?

@jasontedor jasontedor changed the title Disallow type names to contain dots for new indices except for .percolator Disallow type names to start with dots for new indices except for .percolator Aug 5, 2015
@jasontedor
Copy link
Member Author

@clintongormley Given that change, I agree. I've updated the PR.

import org.junit.Test;

public class MapperServiceTest extends ElasticsearchSingleNodeTest {
@Test(expected = IllegalArgumentException.class)
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using expected exception, cant eh test wrap the call in a try/catch, and actually check the exception is what we think it should be? Something like:

try {
    ...prepareIndex...
} catch (IllegalArgumentException e) {
    assertTrue(e.getMessage().contains("must not start with a '.'"));
}

Also I think it would be better to use an explicit create index call with mappings here, instead of relying on dynamic mappings?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree on both counts, thanks!

@alexksikes
Copy link
Contributor

@clintongormley Why would it be a good thing to prevent type names from beginning with a dot? IMHO with this PR aren't we disabling the ability for types to be hidden?

@jpountz
Copy link
Contributor

jpountz commented Aug 10, 2015

I don't think we should allow either applications or plugins to reserve hidden types. I know we have been doing this with the percolator, but I don't think this is something we should replicate.

In order to be useful, hidden types will likely need to store data, so they also need mappings. However in 2.0 we now check much more aggressively that all types have consistent mappings, so whenever a hidden type would add mappings to an index, it would restrict mappings that can be set on other regular types. If a plugin wants to reserve a namespace where it can store data, it should rather go with an index, like elasticsearch-core already does with the .script index and watcher also does with the .watches index.

So +1 to merge and reject type names that start with a dot.

@javanna
Copy link
Member

javanna commented Aug 10, 2015

aren't we disabling the ability for types to be hidden?

I care to clarify that we don't have the ability for types to be hidden. Only the .percolator type is hidden at the moment, just because it is called .percolator not because its name starts with .. That said we are not disabling any feature with this PR. I guess we are just saying that .percolator is enough and we don't want to add the ability for types to be hidden in general. The .percolator type will stay untouched.

@alexksikes
Copy link
Contributor

@javanna thanks for the clarification, makes sense. @jpountz I see where you are coming from, you'd rather encourage people to use an index instead of a new type. I'm thinking we could just restrict the usage of .percolator and that's it (maybe later on a list of reserved system types could be added). It seems that forbidding the . in types by itself doesn't buy us anything IMHO.

@jasontedor
Copy link
Member Author

@alexksikes It reserves an entire class of names (those starting with dot) for future use. We can't reserve names in the future without potentially making breaking changes. This is why we want to do this on a major release when breaking changes are expected.

…rcolator

This commit will disallow type names to start with dots for version 2 and later indices except for .percolator.

Closes #12560
jasontedor added a commit that referenced this pull request Aug 12, 2015
Disallow type names to start with dots for new indices except for .percolator
@jasontedor jasontedor merged commit d56dc78 into elastic:master Aug 12, 2015
@jasontedor jasontedor deleted the feature/12560 branch August 12, 2015 06:40
@jasontedor jasontedor removed the review label Aug 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>breaking :Search/Mapping Index mappings, including merging and defining field types v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants