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

Sub-fields should not accept include_in_all parameter #21971

Merged
merged 4 commits into from Dec 19, 2016
Merged

Sub-fields should not accept include_in_all parameter #21971

merged 4 commits into from Dec 19, 2016

Conversation

makeyang
Copy link
Contributor

@makeyang makeyang commented Dec 5, 2016

Throw an exception when specifying include_in_all on multi-fields

Closes #21710

@nik9000 nik9000 added :Search/Mapping Index mappings, including merging and defining field types >bug labels Dec 5, 2016
Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

Can you add a test for this? I'd probably make an org.elasticsearch.index.mapper.IncludeInAllMapperTests and use org.elasticsearch.index.mapper.CopyToMapperTests as an example.

@@ -229,6 +229,9 @@ public static void parseField(FieldMapper.Builder builder, String name, Map<Stri
builder.indexOptions(nodeIndexOptionValue(propNode));
iterator.remove();
} else if (propName.equals("include_in_all")) {
if(parserContext.isWithinMultiField()) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: usually we put a space between if and (

@@ -229,6 +229,9 @@ public static void parseField(FieldMapper.Builder builder, String name, Map<Stri
builder.indexOptions(nodeIndexOptionValue(propNode));
iterator.remove();
} else if (propName.equals("include_in_all")) {
if(parserContext.isWithinMultiField()) {
throw new MapperParsingException("sub-fields shouldn't contain property: include_in_all, and current node is:" + name);
Copy link
Member

Choose a reason for hiding this comment

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

Have a look at the example below for copy_to about how we usually write these field names. We wrap all the variable bits of exception messages in [] almost everywhere. Right or wrong it is our habit and we should stick to it unless we have a good reason not to.

@makeyang
Copy link
Contributor Author

makeyang commented Dec 8, 2016

@nik9000 I modified code according to your comments. I'll commit test later. but I have one question related to CopyToMapperTests: it seems in this test, this exception:

MapperParsingException("copy_to in multi fields is not allowed. Found the copy_to in field [" + name + "] which is within a multi field.")

is not test?
if so, why? if it is not the truth, tell me some details. thanks

@nik9000
Copy link
Member

nik9000 commented Dec 8, 2016

is not test?

You mean that test doesn't exist? I suspect we just forgot to make it. If you'd like to make it while you are there that'd be lovely.

@makeyang
Copy link
Contributor Author

makeyang commented Dec 8, 2016

@nik9000 it turns out that it is tested but in another test case file:MultiFieldCopyToMapperTests. so I add this new test case file:MultiFieldIncludeInAllMapperTests
please help to review. thanks

@clintongormley clintongormley changed the title fix bug: https://github.com/elastic/elasticsearch/issues/21710 Sub-fields should not accept include_in_all parameter Dec 9, 2016
@makeyang
Copy link
Contributor Author

@nik9000 can you help to review this?

import static org.hamcrest.core.IsEqual.equalTo;

/**
* Created by makeyang on 2016/12/8.
Copy link
Member

Choose a reason for hiding this comment

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

Can you replace this with something descriptive of what it does or remove it?

MapperService mapperService = MapperTestUtils.newMapperService(createTempDir(), Settings.EMPTY);
try {
mapperService.parse("type", new CompressedXContent(mapping.string()), true);
fail("Parsing should throw an exception because the mapping contains a include_in_all in a multi field");
Copy link
Member

Choose a reason for hiding this comment

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

We tend to use expectThrows for this when we write new tests. It isn't required but it is a bit cleaner to read.

2. remove Created by declaration
3. fix typo method name from testExceptionForCopyToInMultiFields to testExceptionForIncludeInAllInMultiFields
4. fix typo method name from createMappinmgWithIncludeInAllInMultiField to createMappingWithIncludeInAllInMultiField
5. use expectThrows rather than try catch according to nik9000's comments
@makeyang
Copy link
Contributor Author

@nik9000 can you help to review this please?

@makeyang
Copy link
Contributor Author

@nik9000 can you help to review this or ask someone else to help to review it? thanks very much.

@nik9000
Copy link
Member

nik9000 commented Dec 19, 2016

Looks right to me!

elasticmachine, please test this.

@nik9000 nik9000 merged commit 2e1d152 into elastic:master Dec 19, 2016
@nik9000
Copy link
Member

nik9000 commented Dec 19, 2016

Thanks @makeyang! I've merged to master and will backport to 5.x:

master: 2e1d152 + 40b80ae
5.x: eae5b30 + 36559c0

nik9000 added a commit that referenced this pull request Dec 19, 2016
Fail to update mapping when multifield has `include_in_all`.

Closes #21710
@makeyang
Copy link
Contributor Author

@nik9000 thanks very much.

@mfeltscher
Copy link

Isn't this a breaking change? This broke our mappings while upgrading from 5.1.x to 5.2.x

@clintongormley
Copy link

@mfeltscher thanks for reporting and yes, this shouldn't have gone into 5.2. i've opened #23654

nik9000 added a commit to nik9000/elasticsearch that referenced this pull request Mar 20, 2017
This reverts elastic#21971 which should only have been applied in master
to preserve backwards compatibility. Instead of throwing an error
when you specify `include_in_all` inside a multifield we instead
return a deprecation warning. `include_in_all` in a multifield
still doesn't do anything. But at least people who use it erroneously
won't break.

Closes elastic#23654
nik9000 added a commit that referenced this pull request Mar 20, 2017
This reverts #21971 which should only have been applied in master
to preserve backwards compatibility. Instead of throwing an error
when you specify `include_in_all` inside a multifield we instead
return a deprecation warning. `include_in_all` in a multifield
still doesn't do anything. But at least people who use it erroneously
won't break.

Closes #23654
nik9000 added a commit that referenced this pull request Mar 20, 2017
This reverts #21971 which should only have been applied in master
to preserve backwards compatibility. Instead of throwing an error
when you specify `include_in_all` inside a multifield we instead
return a deprecation warning. `include_in_all` in a multifield
still doesn't do anything. But at least people who use it erroneously
won't break.

Closes #23654
nik9000 added a commit that referenced this pull request Mar 20, 2017
This reverts #21971 which should only have been applied in master
to preserve backwards compatibility. Instead of throwing an error
when you specify `include_in_all` inside a multifield we instead
return a deprecation warning. `include_in_all` in a multifield
still doesn't do anything. But at least people who use it erroneously
won't break.

Closes #23654
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search/Mapping Index mappings, including merging and defining field types v5.2.0 v6.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants