Skip to content

Add searchable snapshots actions to ILM #50806

@DaveCTurner

Description

@DaveCTurner

Today, here is how to turn an index into a searchable snapshot on the feature/searchable-snapshot branch:

## Create normal repository for taking the snapshot
PUT /_snapshot/backing_repo
{
  "settings": {
    "location": "/Users/davidturner/src/elasticsearch-master/repo/backing"
  },
  "type": "fs"
}

## Create searchable repository for the restore
PUT /_snapshot/searchable_repo
{
  "settings": {
    "location": "/Users/davidturner/src/elasticsearch-master/repo/backing",
    "delegate_type": "fs"
  },
  "type": "searchable"
}

## Create and populate the index
PUT /original
{
  "settings": {
    "index.number_of_replicas": 0
  },
  "aliases": {
    "alias": {}
  }
}

POST /original/_bulk?refresh
{"index":{}}
{"foo":"bar"}
{"index":{}}
{"baz":"quux"}

POST /original/_flush

## Force-merge it to a single segment (optional)

POST /original/_forcemerge?max_num_segments=1

## Verify that there are docs in the index

GET /alias/_search
{
  "size": 0
}

# {
#   "took": 1,
#   "_shards": {
#     "skipped": 0,
#     "successful": 1,
#     "total": 1,
#     "failed": 0
#   },
#   "timed_out": false,
#   "hits": {
#     "max_score": null,
#     "total": {
#       "value": 2,
#       "relation": "eq"
#     },
#     "hits": []
#   }
# }

## Take a snapshot of the target index

POST /_snapshot/backing_repo/snap?wait_for_completion=true
{
  "indices": "original",
  "include_global_state": false
}

## Restore the snapshot to a different name

POST /_snapshot/searchable_repo/snap/_restore
{
  "indices": "original",
  "rename_pattern": "original",
  "rename_replacement": "snapped"
}

GET /_cluster/health?wait_for_status=green

## Adjust the alias to point to the restored index and delete the original index

POST /_aliases
{
  "actions": [
    {
      "add": {
        "alias": "alias",
        "index": "snapped"
      }
    },
    {
      "remove": {
        "alias": "alias",
        "index": "original"
      }
    }
  ]
}

DELETE /original

## Verify that there's still two docs visible to searches

GET /alias/_search
{
  "size": 0
}

# {
#   "took": 2,
#   "_shards": {
#     "skipped": 0,
#     "successful": 1,
#     "total": 1,
#     "failed": 0
#   },
#   "timed_out": false,
#   "hits": {
#     "max_score": null,
#     "total": {
#       "value": 2,
#       "relation": "eq"
#     },
#     "hits": []
#   }
# }

## 🚀

This is too much to expect of our users, and it would be much better if ILM would guide the index through this process instead. We propose an ILM action to convert an index to a searchable snapshot, performing the steps above, to take place after the Force Merge action in the warm phase and after the Freeze action in the cold phase. As of today it is not possible to freeze a searchable snapshot but we may add that functionality in future. It is possible to run the Set Priority, Allocate, and Delete actions on a searchable snapshot.

Of particular note is the snapshotting step: we take a snapshot of the single index. This avoids needing to retain a cluster-wide snapshot simply to preserve this single index. It's important that we retain this snapshot until after the index itself is deleted. Once the index is deleted we may (or may not) want to delete the corresponding snapshot.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions