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

Scripting: ctx[_version] in update by query returns -1 since 6.7 #55745

Closed
stu-elastic opened this issue Apr 24, 2020 · 6 comments · Fixed by #88740
Closed

Scripting: ctx[_version] in update by query returns -1 since 6.7 #55745

stu-elastic opened this issue Apr 24, 2020 · 6 comments · Fixed by #88740
Assignees
Labels
>bug :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache Team:Core/Infra Meta label for core/infra team

Comments

@stu-elastic
Copy link
Contributor

In TransportUpdateByQueryAction we always create AsyncIndexBySearchAction with needsSourceDocumentVersions=false, so the versions are never fetched. This was on the switch to sequence numbers: #37857.

The documentation still refers to ctx['_version'] and we still populate that key in the context.

@stu-elastic stu-elastic added >bug :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache labels Apr 24, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Scripting)

@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Apr 24, 2020
@stu-elastic
Copy link
Contributor Author

TODO: test passing true to fetch version

@stu-elastic
Copy link
Contributor Author

After checking fetch version, let's ask the distrib folks.

@stu-elastic stu-elastic self-assigned this May 14, 2020
@rjernst rjernst added the needs:triage Requires assignment of a team area label label Dec 3, 2020
@stu-elastic stu-elastic removed the needs:triage Requires assignment of a team area label label Dec 9, 2020
@Metalmacher
Copy link

Any update on this? Issue still exists in 7.16.2. Additionally, a similar problem can be observed when trying to set _version from an ingest pipeline:

PUT _ingest/pipeline/version_searchable
{
    "description" : "Moves _version to indexable field version",
    "processors" : [
      {
        "script" : {
          "source" : "ctx.version = ctx._version;"
        }
      }
    ]
}
POST testing_index/_update_by_query?pipeline=version_searchable

Resulting field has -3 for all documents, regardless of the actual _version.

@stu-elastic
Copy link
Contributor Author

To get the version as part of the document you need to pass in version: true to the update by query request.

@stu-elastic
Copy link
Contributor Author

version: true is no longer being honored.

diff --git a/modules/reindex/src/main/java/org/elasticsearch/reindex/TransportUpdateByQueryAction.java b/modules/reindex/src/main/java/org/elasticsearch/reindex/TransportUpdateByQueryAction.java
index 0f1a98ac085..6674a187cdd 100644
--- a/modules/reindex/src/main/java/org/elasticsearch/reindex/TransportUpdateByQueryAction.java
+++ b/modules/reindex/src/main/java/org/elasticsearch/reindex/TransportUpdateByQueryAction.java
@@ -18,6 +18,7 @@ import org.elasticsearch.client.internal.ParentTaskAssigningClient;
 import org.elasticsearch.cluster.ClusterState;
 import org.elasticsearch.cluster.service.ClusterService;
 import org.elasticsearch.common.inject.Inject;
+import org.elasticsearch.core.Booleans;
 import org.elasticsearch.index.reindex.BulkByScrollResponse;
 import org.elasticsearch.index.reindex.BulkByScrollTask;
 import org.elasticsearch.index.reindex.ScrollableHitSource;
@@ -101,7 +102,7 @@ public class TransportUpdateByQueryAction extends HandledTransportAction<UpdateB
             super(
                 task,
                 // use sequence number powered optimistic concurrency control
-                false,
+                Boolean.TRUE.equals(request.getSearchRequest().source().version()),
                 true,
                 logger,
                 client,

stu-elastic added a commit to stu-elastic/elasticsearch that referenced this issue Jul 22, 2022
Allow UpdateByQuery to read the doc version if set in the request via
`version=true`.

If `version=true` is unset or false, the `ctx._version` is `-1`
indicating internal versioning via seq.

Fixes: elastic#55745
stu-elastic added a commit that referenced this issue Jul 26, 2022
Allow UpdateByQuery to read the doc version if set in the request via
`version=true`.

If `version=true` is unset or false, the `ctx._version` is `-1`
indicating internal versioning via seq.

Fixes: #55745
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache Team:Core/Infra Meta label for core/infra team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants