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

if_seq_no & if_primary_term params are ignored #2058

Open
Fieldistor opened this issue Mar 28, 2022 · 1 comment
Open

if_seq_no & if_primary_term params are ignored #2058

Fieldistor opened this issue Mar 28, 2022 · 1 comment

Comments

@Fieldistor
Copy link

Fieldistor commented Mar 28, 2022

In 7.1.0 CHANGELOG.md:
* Added if_seq_no/if_primary_termto replaceversion for [optimistic concurrency control](https://www.elastic.co/guide/en/elasticsearch/reference/7.x/optimistic-concurrency-control.html) [#1803](https://github.com/ruflin/Elastica/pull/1803)

But, even if you can set these params on Action Object - they are ignored (on any version of the library, 7.1.0+).
Example of the source code, where exception should arise (because seqNo is incorrect), but doc changes are applied instead:

  $client = $this->factory->getClient();
  $bulk = new \Elastica\Bulk($client);

  $index = new Elastica\Index($client, 'foo');
  $doc = $index->getDocument("bar");
  $_seq_no = $doc->getSequenceNumber() -1 ;
  $_primary_term = $doc->getPrimaryTerm();

  $dDocUpdate = new \Elastica\Document(
      "bar",
      array('d' => 22235),
      'foo'
  );

  $dDocUpdate
      ->setDocAsUpsert(false)
      ->setSequenceNumber($_seq_no)
      ->setPrimaryTerm($_primary_term);
  
  $bulk->addAction(new \Elastica\Bulk\Action\UpdateDocument($dDocUpdate));

  $r = $bulk->send();
  
  $g = 0;

Folowing quick fix in ruflin/elastica/src/Bulk/Action/IndexDocument.php solves the problem:

    /**
     * {@inheritdoc}
     */
    protected function _getMetadata(AbstractUpdateAction $action): array
    {
        return $action->getOptions([
            '_index',
            '_id',
            'version',
            'version_type',
            'routing',
            'parent',
            'retry_on_conflict',
            'if_seq_no',
            'if_primary_term'
        ]);
    }
@ruflin
Copy link
Owner

ruflin commented Mar 29, 2022

@Fieldistor Interested to open a PR against the repo with the change? This should make discussions much easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants