1

I'm using ElasticSearch in my Laravel app and recently I've implemented the option to allow for deletion of documents from the Elastic Search index. The problem is that I keep getting the version_conflict_engine_exception error.

My code looks like this:

$params = [
    'index' => 'invoices',
    'body' => [
        'query' => [
            'bool' => [
                'must' => [
                    ['term' => ['user_id' => $userId]]
                ]
            ]
        ]
    ],
    'refresh' => true,
];

Elasticsearch::deleteByQuery($params);

After reading the official docs I get that a 'conflicts' => 'proceed' parameter can be added and this should solve the problem. But I feel like I'm only hiding the issue, not actually solving it. I know for sure that no other operation is performed on that document in the same time, so no reason for the version to change, but this error keeps popping up.

{
  "took": 1189,
  "timed_out": false,
  "total": 47,
  "deleted": 0,
  "batches": 1,
  "version_conflicts": 47,
  "noops": 0,
  "retries": {
    "bulk": 0,
    "search": 0
  },
  "throttled_millis": 0,
  "requests_per_second": -1,
  "throttled_until_millis": 0,
  "failures": {
    "index": "invoices",
    "type": "_doc",
    "id": "6e6bd47a-c225-4d7f-8798-cc1275b0363c",
    "cause": {
      "type": "version_conflict_engine_exception",
      "reason": "[6e6bd47a-c225-4d7f-8798-cc1275b0363c]: version conflict, required seqNo [667648], primary term [7]. but no document was found",
      "index_uuid": "7wBzPBXYT4Kfx8jP1SjSNA",
      "shard": "0",
      "index": "invoices"
    },
    "status": 409
  }
}

Could there be something else to this that I'm doing wrong?

Cosmin
  • 864
  • 3
  • 16
  • 34
  • Can you show the full `version_conflict_engine_exception` error that you get? – Val Aug 16 '21 at 14:49
  • Updated the post with the exception details. – Cosmin Aug 16 '21 at 14:59
  • 1
    This could happen if you (for some reason) send this query twice at the same time. ElasticSearch first determines the Ids to delete and then deletes them so if you do this twice at the same time both queries might determine the same ids but only one will get to delete them. I know you said you know no other query is performed at the same time, but are you absolutely sure? How are you calling this query? – apokryfos Aug 16 '21 at 15:26
  • What is the refresh interval on the `invoices` index? – Val Aug 16 '21 at 15:33
  • 1
    @apokryfos, the query is called as shown in the example above. I'm using [this](https://github.com/cviebrock/laravel-elasticsearch) package. – Cosmin Aug 16 '21 at 15:41
  • @Val, will check that, I don't know exactly. – Cosmin Aug 16 '21 at 15:42
  • @Val, the refresh interval is the default one, 1 second. – Cosmin Aug 17 '21 at 07:34
  • @Cosmin did you ever find the solution to this? – tomvo Jul 13 '22 at 13:41

0 Answers0