{"id":19915633,"url":"https://github.com/andreafspeziale/opensearch-scripts","last_synced_at":"2025-05-03T05:32:34.619Z","repository":{"id":159490153,"uuid":"627867281","full_name":"andreafspeziale/opensearch-scripts","owner":"andreafspeziale","description":"Fast and easy to use opensearch connection and operations scripts 🔍","archived":false,"fork":false,"pushed_at":"2024-07-17T17:56:07.000Z","size":830,"stargazers_count":2,"open_issues_count":11,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-07-17T21:59:55.545Z","etag":null,"topics":["aws","nodejs","opensearch","scripts","search-engine"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andreafspeziale.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-14T11:28:39.000Z","updated_at":"2024-06-05T08:50:55.000Z","dependencies_parsed_at":"2024-04-03T17:29:16.716Z","dependency_job_id":"e2cb6ba6-0498-46f4-954c-b9b95733b16f","html_url":"https://github.com/andreafspeziale/opensearch-scripts","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreafspeziale%2Fopensearch-scripts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreafspeziale%2Fopensearch-scripts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreafspeziale%2Fopensearch-scripts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreafspeziale%2Fopensearch-scripts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreafspeziale","download_url":"https://codeload.github.com/andreafspeziale/opensearch-scripts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224354685,"owners_count":17297406,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","nodejs","opensearch","scripts","search-engine"],"created_at":"2024-11-12T21:41:32.466Z","updated_at":"2025-05-03T05:32:34.614Z","avatar_url":"https://github.com/andreafspeziale.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Opensearch scripts\n\n\u003e Recently learned about the existance of the official [opensearch-cli](https://opensearch.org/docs/latest/tools/cli/)\n\n\u003e This repository evolved in my [os-cli](https://github.com/andreafspeziale/os-cli)\n\nFast and easy to use opensearch connection and operations scripts.\n\n## Quickstart\n\n- `cp ./env/.env.development .env`\n- `cp ./src/config.example.ts ./src/config.ts`\n- `docker compose up -d`\n\n\u003e Eventually reload the TS server\n\n- `pnpm i`\n- `pnpm create:index`\n- `pnpm create:doc`\n- `pnpm query:doc`\n\nCheck the available scripts in the `package.json` scripts section.\n\n## Example\n\n![example](./example.png)\n\n## Docker\n\nThe docker compose has been extracted and simplified from the [official documentation](https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/#sample-docker-compose-file-for-development).\n\n## Environment variables\n\n- `OPENSEARCH_HOST`\n\nRequired: _true_ \\\nDescription: your opensearch instance host.\n\n- `CONNECTION_METHOD`\n\nRequired: _true_ \\\nDescription: sets opensearch client accordingly. \\\nValues: [`local`, `proxy`, `serviceAccount`, `credentials`]\n\n\u003e `local` when using Docker locally or when using an `AwsSigv4` [proxy](https://github.com/awslabs/aws-sigv4-proxy)\n\n- `AWS_REGION | AWS_DEFAULT_REGION`\n\nRequired: when _CONNECTION_METHOD_ is _serviceAccount_ or _credentials_ \\\nDescription: the AWS region.\n\n- `AWS_ROLE_ARN`\n\nRequired: when _CONNECTION_METHOD_ is _serviceAccount_ \\\nDescription: the AWS role ARN injected by the serviceAccount.\n\n- `AWS_WEB_IDENTITY_TOKEN_FILE`\n\nRequired: when _CONNECTION_METHOD_ is _serviceAccount_ \\\nDescription: the AWS web identity toke file injected by the serviceAccount.\n\n- `AWS_ACCESS_KEY_ID`\n\nRequired: when _CONNECTION_METHOD_ is _credentials_ \\\nDescription: the AWS access key Id.\n\n- `AWS_SECRET_ACCESS_KEY`\n\nRequired: when _CONNECTION_METHOD_ is _credentials_ \\\nDescription: the AWS secret access key.\n\n## Recipes\n\nAfter seeding OpenSearch following the Quickstart you can try out the following recipes.\n\n### Taking a Snapshot\n\n- `pnpm run get:snapshot:repos` check if any snapshot repository has been ever created, it should be empty\n- `pnpm run create:snapshot:repo` will create a repository named as configured (default: `snapshot-repository`)\n\nYou should now able to see something like this after checking out the first command again:\n\n```\nGet repositories response:  {\n  'snapshot-repository': {\n    type: 'fs',\n    settings: {\n      location: '/usr/share/opensearch/data/snapshots/snapshot-repository'\n    }\n  }\n}\n```\n\n- `pnpm run create:snapshot` will creates your first snapshot\n- `pnpm run get:snapshot:all` check all the snapshots for the created repository\n\nThe response should be something like this:\n\n```\nGet snapshots from repository response:  {\n  snapshots: [\n    {\n      snapshot: 'snapshot-0',\n      uuid: 'f5nBUxLSRfSJKDMB0AVm6Q',\n      version_id: 136277827,\n      version: '2.6.0',\n      indices: [Array],\n      data_streams: [],\n      include_global_state: true,\n      state: 'SUCCESS',\n      start_time: '2023-06-23T10:50:22.579Z',\n      start_time_in_millis: 1687517422579,\n      end_time: '2023-06-23T10:50:22.579Z',\n      end_time_in_millis: 1687517422579,\n      duration_in_millis: 0,\n      failures: [],\n      shards: [Object]\n    }\n  ]\n}\n```\n\n### Restoring a Snapshot withing same instance\n\nNow let's DROP the index in order to restore it\n\n- `pnpm run list:index` check the index list\n\nThe response should be something like this:\n\n```\nList index response:  [\n  ...\n  {\n    health: 'green',\n    status: 'open',\n    index: 'books',\n    uuid: 'NTiBDO4GSDCQDlg6CJyCPQ',\n    pri: '1',\n    rep: '1',\n    'docs.count': '3',\n    'docs.deleted': '1',\n    'store.size': '8.1kb',\n    'pri.store.size': '8.1kb'\n  },\n  ...\n]\n```\n\n- `pnpm run delete:index` drop the index\n\nThe `books` index should be missing, you can check it out by running the first command again.\n\nNow let's restore the dropped index\n\n- `pnpm run restore:snapshot`\n\nThe `books` index should be restored, you can check it out by running the first command again.\n\nAnother common use-case could be the restore of the index after dropping just an index element (`pnpm run delete:doc`). In this case the index should be manually `closed` (`pnpm run close:index`) preventing it to be updated by any parallel process. After that you will able to restore it as showed above.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreafspeziale%2Fopensearch-scripts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreafspeziale%2Fopensearch-scripts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreafspeziale%2Fopensearch-scripts/lists"}