searchkick resource_already_exists_exception

sugiarto - Sep 2 - - Dev Community

Yesterday, I worked on elasticsearch integration with help of searchkick.

I did several times adding searchkick to Rails projects but never got this error before:

`__raise_transport_error': [400] {"error":{"root_cause":[{"type":"resource_already_exists_exception","reason":"index [house_development_20240902225059955/3Jvd0sYAT46lRDc8O-CgDQ] already exists"
Enter fullscreen mode Exit fullscreen mode

This error was raised when I ran

MyModel.reindex
Enter fullscreen mode Exit fullscreen mode

From the error description, I can say the problem is index already exists and failed to recreate the index. So I tried to delete the index using curl,

show all indexes.

curl http://elastic:ELASTICSEARCH_PASSSWORD@127.0.0.1:9200/_aliases?pretty=true
Enter fullscreen mode Exit fullscreen mode

delete index.

curl -X DELETE http://elastic:CbHBbB9PS5xYB5RdOTQP@127.0.0.1:9200/house_development_20240902225059955
Enter fullscreen mode Exit fullscreen mode

After that, then I tried to call MyModel.reindex again, but the same error still happened.

Then I tried to check the elasticsearch server log and got this:

high disk watermark [90%] exceeded on [WPlL99sKQ7CnX59V0PiC-Q][cc376a2237d1][/usr/share/elasticsearch/data] free: 47.2gb[9.9%], shards will be relocated away from this node; currently relocating away shards totalling [0] bytes; the node is expected to continue to exceed the high disk watermark when these relocations are complete
Enter fullscreen mode Exit fullscreen mode

After googling, I found this SO question, and just tried to change threshold_enabled that made indexing back to work.

curl -XPUT "http://elastic:ELASTICSEARCH_PASSSWORD@127.0.0.1:9200/_cluster/settings" \
 -H 'Content-Type: application/json' -d'
{
  "persistent": {
    "cluster": {
      "routing": {
        "allocation.disk.threshold_enabled": false
      }
    }
  }
}'

Enter fullscreen mode Exit fullscreen mode

Hope this helps for you.

. . . . . . . . . . . .