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

Update cluster state with type mapping also for failed indexing request #8692

Closed

Conversation

brwe
Copy link
Contributor

@brwe brwe commented Nov 27, 2014

When indexing of a document with a type that is not in the mappings fails,
for example because "dynamic": "strict" but doc contains a new field,
then the type is still created on the node that executed the indexing request.
However, the change was never added to the cluster state.
This commit makes sure mapping updates are always added to the cluster state
even if indexing of a document fails.

closes #8650

client().admin().indices().prepareCreate("index").addMapping("_default_", defaultMapping).get();

try {
client().prepareIndex("index", "type", "id").setSource("{\"test\":\"test\"}").get();
Copy link
Member

Choose a reason for hiding this comment

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

You can just use setSource("test", "test")?

…xing request

When indexing of a document with a type that is not in the mappings fails,
for example because "dynamic": "strict" but doc contains a new field,
then the type is still created on the node that executed the indexing request.
However, the change was never added to the cluster state.
This commit makes sure mapping updates are always added to the cluster state
even if indexing of a document fails.

closes elastic#8650
@brwe brwe force-pushed the fix-type-mapping-update-on-indexing-failure branch from 73845eb to 299abe1 Compare February 23, 2015 17:50
@brwe
Copy link
Contributor Author

brwe commented Feb 23, 2015

Updated. I also moved the integration test to a separate class as DedicatedAggregationTests is hardly the right place.



public class WriteFailure extends ElasticsearchException implements ElasticsearchWrapperException {
@Nullable
Copy link
Member

Choose a reason for hiding this comment

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

Why is this nullable when there is an assert forbidding null in the ctor?

Copy link
Member

Choose a reason for hiding this comment

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

ignore, im blind. :)

@rjernst
Copy link
Member

rjernst commented Feb 23, 2015

@brwe I started looking at this again, but then realized I'm not sure this is what we want. Isn't the point of dynamic: strict to not modify mappings? Adding an empty type in this case seems counter intuitive...

@brwe
Copy link
Contributor Author

brwe commented Feb 24, 2015

Isn't the point of dynamic: strict to not modify mappings?

dynamic: strict means that no fields may be added that were not defined before. The setting for strictly not adding pre defined types is "index.mapper.dynamic": false.

However, I agree it is weird that the mapping is created although the document is not indexed. We create mappings in some places where we then do not index, like index failures in bulk requests (see #5623) or when percolating a document that has a type which was not defined before.
The reason why we do this is that currently mappings are added to the node local DocumentMapper the moment we parse. This means that we have to update the mapping, regardless of if the document is indexed or not because else the mapping in cluster state and in DocumentMapper are out of sync and therefore the mapping is lost the moment we restart the node.
While reading the code I actually found another example where this causes problems: When we parse a document halfway and then get a parsing exception, the parsed fields that were added before are then also not added to the cluster state and can be lost when restarting the node. I added a test and fix to this pr.
Now, I think we have two options:

  • fix: Parsing of documents that are not indexed should not change the Document mapper or the mapping in the cluster state
  • push the fixes as is which would at least prevent the mappings to be lost and live with the fact that mappings are created even if indexing of the doc fails.

I would like to do the latter and work on the first in a different issue and pr because I could imagine this needs a little more work.

@rjernst
Copy link
Member

rjernst commented Feb 24, 2015

I'm all for making the behavior consistent and predictable. What concerns me is the future, when mappings are cleaned up and immutable (#9365) so that we can fix all of these issues you mention and not modify mappings when failures occur. I do not want someone to then argue the current behavior needs to be maintained. So can we downplay this in the docs somehow? I don't want anyone to rely on this behavior, or even have the expectation of relying on the behavior.

@rjernst
Copy link
Member

rjernst commented Feb 24, 2015

Obviously this PR has no doc changes. I guess what I mean is, can we maintain the fact that this behavior cannot be relied upon if someone comes along and says "what is the behavior and why isn't it documented?".

This question aside, the change LGTM.

@brwe
Copy link
Contributor Author

brwe commented Feb 24, 2015

ok, changed WriteFailure -> WriteFailureException. Will push in a minute to 1.4 1.x and master

@brwe
Copy link
Contributor Author

brwe commented Feb 24, 2015

spoke too soon. the second fix should also be in prepareIndex and not just prepareCreate. Also, I am not sure if it is sufficient to check if it was a MapperParsingException but also we should probably check if the mapping was actually modified before we update on master.

@brwe
Copy link
Contributor Author

brwe commented Feb 24, 2015

I'll push only the original fix (mapping lost with dynamic_strict...) and make a separate issue for the second one.

@brwe brwe closed this in ff8fd67 Feb 24, 2015
brwe added a commit that referenced this pull request Feb 24, 2015
…xing request

When indexing of a document with a type that is not in the mappings fails,
for example because "dynamic": "strict" but doc contains a new field,
then the type is still created on the node that executed the indexing request.
However, the change was never added to the cluster state.
This commit makes sure mapping updates are always added to the cluster state
even if indexing of a document fails.

closes #8692
relates to #8650
brwe added a commit that referenced this pull request Feb 24, 2015
…xing request

When indexing of a document with a type that is not in the mappings fails,
for example because "dynamic": "strict" but doc contains a new field,
then the type is still created on the node that executed the indexing request.
However, the change was never added to the cluster state.
This commit makes sure mapping updates are always added to the cluster state
even if indexing of a document fails.

closes #8692
relates to #8650
@javanna
Copy link
Member

javanna commented Feb 25, 2015

@brwe can you please label? :)

@brwe brwe added v2.0.0-beta1 v1.5.0 :Search/Mapping Index mappings, including merging and defining field types v1.4.5 and removed review labels Feb 25, 2015
@clintongormley clintongormley changed the title mappings: update cluster state with type mapping also for failed indexin... Update cluster state with type mapping also for failed indexing request Jun 7, 2015
mute pushed a commit to mute/elasticsearch that referenced this pull request Jul 29, 2015
…xing request

When indexing of a document with a type that is not in the mappings fails,
for example because "dynamic": "strict" but doc contains a new field,
then the type is still created on the node that executed the indexing request.
However, the change was never added to the cluster state.
This commit makes sure mapping updates are always added to the cluster state
even if indexing of a document fails.

closes elastic#8692
relates to elastic#8650
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 v1.4.5 v1.5.0 v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mapping potentially lost with "dynamic" : "strict", _default_ mapping and failed document index
4 participants