{"id":13836106,"url":"https://github.com/fastify/fastify-elasticsearch","last_synced_at":"2025-04-05T01:05:27.846Z","repository":{"id":30015348,"uuid":"123586522","full_name":"fastify/fastify-elasticsearch","owner":"fastify","description":"Fastify plugin for Elasticsearch","archived":false,"fork":false,"pushed_at":"2025-03-28T06:44:48.000Z","size":129,"stargazers_count":44,"open_issues_count":1,"forks_count":16,"subscribers_count":15,"default_branch":"main","last_synced_at":"2025-03-28T07:31:30.249Z","etag":null,"topics":["fastify","fastify-plugin"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/@fastify/elasticsearch","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fastify.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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},"funding":{"github":"fastify","open_collective":"fastify"}},"created_at":"2018-03-02T14:06:17.000Z","updated_at":"2025-03-28T06:44:49.000Z","dependencies_parsed_at":"2024-01-25T20:02:07.753Z","dependency_job_id":"ef8aaf0f-1d7a-4338-addd-6a399b5e5537","html_url":"https://github.com/fastify/fastify-elasticsearch","commit_stats":{"total_commits":131,"total_committers":24,"mean_commits":5.458333333333333,"dds":0.6641221374045801,"last_synced_commit":"981fdcfe9de8c7ad95624e1ce84b5909143d123b"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Ffastify-elasticsearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Ffastify-elasticsearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Ffastify-elasticsearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Ffastify-elasticsearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastify","download_url":"https://codeload.github.com/fastify/fastify-elasticsearch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271522,"owners_count":20911587,"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":["fastify","fastify-plugin"],"created_at":"2024-08-04T15:00:35.699Z","updated_at":"2025-04-05T01:05:27.831Z","avatar_url":"https://github.com/fastify.png","language":"JavaScript","readme":"# @fastify/elasticsearch\n\n[![CI](https://github.com/fastify/fastify-elasticsearch/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/fastify-elasticsearch/actions/workflows/ci.yml)\n[![NPM version](https://img.shields.io/npm/v/@fastify/elasticsearch.svg?style=flat)](https://www.npmjs.com/package/@fastify/elasticsearch)\n[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)\n\nFastify plugin for [Elasticsearch](https://www.elastic.co/elasticsearch/) for sharing the same ES client in every part of your server.\nUnder the hood, the official [elasticsearch](https://www.npmjs.com/package/@elastic/elasticsearch) module is used.\n\n\n## Install\n\n```\nnpm i @fastify/elasticsearch\n```\n\n### Compatibility\n| Plugin version | Fastify version |\n| ---------------|-----------------|\n| `\u003e=4.x`        | `^5.x`          |\n| `^3.x`         | `^4.x`          |\n| `^2.x`         | `^3.x`          |\n| `^1.x`         | `^2.x`          |\n| `^1.x`         | `^1.x`          |\n\n\nPlease note that if a Fastify version is out of support, then so are the corresponding versions of this plugin\nin the table above.\nSee [Fastify's LTS policy](https://github.com/fastify/fastify/blob/main/docs/Reference/LTS.md) for more details.\n\n## Usage\nAdd it to your project with `register` and you are done!\nThe plugin accepts the [same options](https://github.com/elastic/elasticsearch-js#client-options) as the client.\n\n```js\nconst fastify = require('fastify')()\n\nfastify.register(require('@fastify/elasticsearch'), { node: 'http://localhost:9200' })\n\nfastify.get('/user', async function (req, reply) {\n  const { body } = await this.elastic.search({\n    index: 'tweets',\n    body: {\n      query: { match: { text: req.query.q }}\n    }\n  })\n\n  return body.hits.hits\n})\n\nfastify.listen({ port: 3000 }, err =\u003e {\n  if (err) throw err\n})\n```\n\nBy default, `@fastify/elasticsearch` will try to ping the cluster as soon as you start Fastify, but in some cases pinging may not be supported due to the user permissions. If you want, you can disable the initial ping with the `healthcheck` option:\n```js\nfastify.register(require('@fastify/elasticsearch'), {\n  node: 'http://localhost:9200',\n  healthcheck: false\n})\n```\n\nIf you need to connect to different clusters, you can also pass a `namespace` option:\n```js\nconst fastify = require('fastify')()\n\nfastify.register(require('@fastify/elasticsearch'), {\n  node: 'http://localhost:9200',\n  namespace: 'cluster1'\n})\n\nfastify.register(require('@fastify/elasticsearch'), {\n  node: 'http://localhost:9201',\n  namespace: 'cluster2'\n})\n\nfastify.get('/user', async function (req, reply) {\n  const { body } = await this.elastic.cluster1.search({\n    index: 'tweets',\n    body: {\n      query: { match: { text: req.query.q }}\n    }\n  })\n\n  return body.hits.hits\n})\n\nfastify.listen({ port: 3000 }, err =\u003e {\n  if (err) throw err\n})\n```\n\n## Versioning\nBy default the latest and greatest version of the Elasticsearch client is used, see the [compatibility](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/introduction.html#_compatibility) table to understand if the embedded client is correct for you.\nIf it is not, you can pass a custom client via the `client` option.\n```js\nconst fastify = require('fastify')()\nconst { Client } = require('@elastic/elasticsearch')\n\nfastify.register(require('@fastify/elasticsearch'), {\n  client: new Client({ node: 'http://localhost:9200' })\n})\n\nfastify.get('/user', async function (req, reply) {\n  const { body } = await this.elastic.search({\n    index: 'tweets',\n    body: {\n      query: { match: { text: req.query.q }}\n    }\n  })\n\n  return body.hits.hits\n})\n\nfastify.listen({ port: 3000 }, err =\u003e {\n  if (err) throw err\n})\n```\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","funding_links":["https://github.com/sponsors/fastify","https://opencollective.com/fastify"],"categories":["\u003ch2 align=\"center\"\u003eAwesome Fastify\u003c/h2\u003e"],"sub_categories":["\u003ch2 align=\"center\"\u003eEcosystem\u003c/h2\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastify%2Ffastify-elasticsearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastify%2Ffastify-elasticsearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastify%2Ffastify-elasticsearch/lists"}