{"id":20129322,"url":"https://github.com/aicore/elasticsearch-lib","last_synced_at":"2025-04-09T16:09:03.680Z","repository":{"id":40589155,"uuid":"451375443","full_name":"aicore/elasticsearch-lib","owner":"aicore","description":"Javascript module for Elasticsearch","archived":false,"fork":false,"pushed_at":"2025-04-04T22:45:45.000Z","size":154,"stargazers_count":0,"open_issues_count":13,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-09T16:08:58.246Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aicore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2022-01-24T08:19:20.000Z","updated_at":"2022-01-24T08:19:25.000Z","dependencies_parsed_at":"2023-02-08T01:47:32.567Z","dependency_job_id":"a1c51deb-20ce-4ca0-ba84-b8adeb06a480","html_url":"https://github.com/aicore/elasticsearch-lib","commit_stats":{"total_commits":21,"total_committers":6,"mean_commits":3.5,"dds":0.6666666666666667,"last_synced_commit":"6adda4466d09a8a6b740ed4231ac99eac7743192"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":"aicore/template-nodejs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aicore%2Felasticsearch-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aicore%2Felasticsearch-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aicore%2Felasticsearch-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aicore%2Felasticsearch-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aicore","download_url":"https://codeload.github.com/aicore/elasticsearch-lib/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065283,"owners_count":21041871,"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":[],"created_at":"2024-11-13T20:33:34.212Z","updated_at":"2025-04-09T16:09:03.659Z","avatar_url":"https://github.com/aicore.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# elastic-search-lib\nModule written in nodejs to integrate easily with Elastic Search. It has additional integrations to support linting, testing,\ncoverage, reporting, GitGub actions for publishing to npm repository, dependency updates and other goodies.\n\nEasily use this module to interact with the ElasticSearch Engine.\n\n# What is ElasticSearch?\nElasticsearch is a distributed, free and open search and analytics engine for all types of data, including textual, numerical, geospatial, structured, and unstructured. Elasticsearch is built on Apache Lucene and was first released in 2010 by Elasticsearch N.V. (now known as Elastic). Known for its simple REST APIs, distributed nature, speed, and scalability, Elasticsearch is the central component of the Elastic Stack, a set of free and open tools for data ingestion, enrichment, storage, analysis, and visualization. Commonly referred to as the ELK Stack (after Elasticsearch, Logstash, and Kibana), the Elastic Stack now includes a rich collection of lightweight shipping agents known as Beats for sending data to Elasticsearch.\n\nFor more details, please refer: https://www.elastic.co/what-is/elasticsearch \n\n## Code Guardian\n[![\u003capp\u003e build verification](https://github.com/aicore/template-nodejs/actions/workflows/build_verify.yml/badge.svg)](https://github.com/aicore/template-nodejs/actions/workflows/build_verify.yml)\n\n\u003ca href=\"https://sonarcloud.io/summary/new_code?id=aicore_elasticsearch-lib\"\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_elasticsearch-lib\u0026metric=alert_status\" alt=\"Sonar code quality check\" /\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_elasticsearch-lib\u0026metric=security_rating\" alt=\"Security rating\" /\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_elasticsearch-lib\u0026metric=vulnerabilities\" alt=\"vulnerabilities\" /\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_elasticsearch-lib\u0026metric=coverage\" alt=\"Code Coverage\" /\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_elasticsearch-lib\u0026metric=bugs\" alt=\"Code Bugs\" /\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_elasticsearch-lib\u0026metric=reliability_rating\" alt=\"Reliability Rating\" /\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_elasticsearch-lib\u0026metric=sqale_rating\" alt=\"Maintainability Rating\" /\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_elasticsearch-lib\u0026metric=ncloc\" alt=\"Lines of Code\" /\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_elasticsearch-lib\u0026metric=sqale_index\" alt=\"Technical debt\" /\u003e\n\u003c/a\u003e\n\n\n# Usage Instrcution\n\n## Installing\n\nInstall it directly using npm by running the command below:\n\n``\nnpm i @aicore/template-nodejs\n``\n\n## Prerequisites\nInorder to use this module, elasticsearch should be installed on the server/local machine. Please refer to the links below:\n\n1. https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html\n2. https://www.linode.com/docs/guides/databases/elasticsearch/\n\n### **List of Available Operations:**\n* createIndices\n* bulkInsert\n* bulkUpdate\n* bulkDelete\n* search\n* get\n\n\n## Code Usage\n\n### **1. createIndices**\n\nCreate Index API is used to manually create an index in Elasticsearch. All documents in Elasticsearch are stored inside of one index or another. Please refer API docs for more details.\n* https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-create-index.html \n\n#### **Required Parameters**\n\n - **nodeAddress (Type: String)**: Complete URL endpoint of the node including port. For e.g http://165.34.23.1:9200/\n - **mappingObject (Type: JSON Object)**: omposite object according to elastic search standards.\n#### **Example**\n ```js\n // import the module directly after installation\n import searchClient from '@aicore/elasticsearch-lib';\n\n const indices = {\n        index: indexName,\n        body: {\n            mappings: {\n                extension_registry_beta: {\n                    properties: {\n                        name: { type: 'text' },\n                        title: { type: 'text' },\n                        description: { type: 'text'}\n                    }\n                }\n            }\n        }\n    };\n\n    const indexResponse = await searchClient.createIndices(nodeAddress, indices);\n\n    console.log(\"Create Index response received :\" + JSON.stringify(indexResponse));\n     //Sample log: https://pastebin.com/1e1axYQE\n \n ```\n### **2. bulkInsert/bulkUpdate/bulkDelete**\n\nPerforms multiple indexing or delete operations in a single API call. This reduces overhead and can greatly increase indexing speed. Please refer API docs for more details.\n * https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-bulk.html?spm=a2c4g.11186623.0.0.636e25b7I4qrj1\n\n  \n   #### **Required Parameters**\n\n- **nodeAddress (Type: String)**: Complete URL endpoint of the node including port. For e.g http://165.34.23.1:9200/\n- **indexName (Type: String)**: Unique identifier for index.\n- **datasets (Type: Array)**: Array of data objects for bulk insert.\n\n **Please Note: The bulkInsert, bulkUpdate and bulkDelete modules all use the same underlying elasticSearch bulk API so the usage is similar to each other.**\n#### **Example**\n\n ```js\n //import the module\n import searchClient from '@aicore/elasticsearch-lib'\n//array of data objects to be inserted\nconst dataset = [\n        {\n            name: 'Theme101',\n            title: 'Brackets',\n            description: 'Provides ability to use code snippets in Brackets.',\n            homepage: 'https://github.com/jrowny/brackets-snippets',\n            author: {\n                name: 'demo',\n                email: 'test@gmail.com'\n            }\n        }];\n\nconst bulkInsertResponse = await searchClient.bulkInsert(nodeAddress, indexName, dataset);\n\nconsole.log(\"Bulk Insert Response \" + JSON.stringify(bulkInsertResponse));\n ```\n\n### **3. search**\nThe search API allows you to execute a search query and get back search hits that match the query.Please refer API docs for more details.\n * https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-search.html\n\n#### **Required Parameters**\n\n- **nodeAddress (Type: String)**: Complete URL endpoint of the node including port. For e.g http://165.34.23.1:9200/\n- **indexName (Type: String)**: Unique identifier for index.\n- **searchQuery (Type: JSON Object)**: containing search parameters. Refer API docs for format\n#### **Example**\n```js\n////import the module\nimport searchClient from '@aicore/elasticsearch-lib';\n//composite searchQuery object to retrieve all results\nconst searchQuery = {\n        index: indexName,\n        body: {\n            query: {\n                match_all: {}\n            }\n        }\n    };\n\nconst searchResponse = await searchClient.search(nodeAddress, indexName, searchQuery);\n```\n### **4. get**\n\nThe get API allows to get a typed JSON document from the index based on its id. Please refer API docs for more details.\n * https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html\n\n#### **Required Parameters**\n - **nodeAddress (Type: String)**: Complete URL endpoint of the node including port. For e.g http://165.34.23.1:9200/\n- **indexName (Type: String)**: Unique identifier for index.\n- **getQuery (Type: JSON Object)**: Composite object containing get parameters. Refer API docs for format\n\n#### **Example**\n```js\n////import the module\nimport searchClient from '@aicore/elasticsearch-lib';\n\nconst getQuery = {\n    index: 'game-of-thrones',\n    id: '1'\n};\n\nconst getResponse = await searchClient.get(nodeAddress, indexName, getQuery);\n\nconsole.log(getResponse);\n\n```\n\n\n# Commands available\n\n## Building\nSince this is a pure JS template project, build command just runs test with coverage.\n```shell\n\u003e npm install   // do this only once.\n\u003e npm run build\n```\n\n## Linting\nTo lint the files in the project, run the following command:\n```shell\n\u003e npm run lint\n```\nTo Automatically fix lint errors:\n```shell\n\u003e npm run lint:fix\n```\n\n## Testing\nTo run all tests:\n```shell\n\u003e npm run test\n  Hello world Tests\n    ✔ should return Hello World\n    #indexOf()\n      ✔ should return -1 when the value is not present\n```\n\nAdditionally, to run unit/integration tests only, use the commands:\n```shell\n\u003e npm run test:unit\n\u003e npm run test:integ\n```\n\n## Coverage Reports\nTo run all tests with coverage:\n\n```shell\n\u003e npm run cover\n  Hello world Tests\n    ✔ should return Hello World\n    #indexOf()\n      ✔ should return -1 when the value is not present\n\n\n  2 passing (6ms)\n\n----------|---------|----------|---------|---------|-------------------\nFile      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s \n----------|---------|----------|---------|---------|-------------------\nAll files |     100 |      100 |     100 |     100 |                   \n index.js |     100 |      100 |     100 |     100 |                   \n----------|---------|----------|---------|---------|-------------------\n\n=============================== Coverage summary ===============================\nStatements   : 100% ( 5/5 )\nBranches     : 100% ( 2/2 )\nFunctions    : 100% ( 1/1 )\nLines        : 100% ( 5/5 )\n================================================================================\nDetailed unit test coverage report: file:///template-nodejs/coverage-unit/index.html\nDetailed integration test coverage report: file:///template-nodejs/coverage-integration/index.html\n```\nAfter running coverage, detailed reports can be found in the coverage folder listed in the output of coverage command.\nOpen the file in browser to view detailed reports.\n\nTo run unit/integration tests only with coverage\n```shell\n\u003e npm run cover:unit\n\u003e npm run cover:integ\n```\n\nSample coverage report:\n![image](https://user-images.githubusercontent.com/5336369/148687351-6d6c12a2-a232-433d-ab62-2cf5d39c96bd.png)\n\n### Unit and Integration coverage configs\nUnit and integration test coverage settings can be updated by configs `.nycrc.unit.json` and `.nycrc.integration.json`.\n\nSee https://github.com/istanbuljs/nyc for config options.\n\n# Publishing packages to NPM\nTo publish a package to npm, push contents to `npm` branch in \nthis repository. \n\n## Publishing `@aicore/package*`\nIf you are looking to publish to package owned by core.ai, you will need access to the GitHub Organization secret `NPM_TOKEN`.\n\nFor repos managed by [aicore](https://github.com/aicore) org in GitHub, Please contact your Admin to get access to core.ai's NPM tokens.\n\n\n## Publishing to your own npm account\nAlternatively, if you want to publish the package to your own npm account, please follow these docs:\n1. Create an automation access token by following this [link](https://docs.npmjs.com/creating-and-viewing-access-tokens).\n2. Add NPM_TOKEN to your repository secret by following this [link](https://docs.npmjs.com/using-private-packages-in-a-ci-cd-workflow)\n\nTo edit the publishing workflow, please see file: `.github/workflows/npm-publish.yml`\n\n\n# Dependency updates\n  We use Rennovate for dependency updates: https://blog.logrocket.com/renovate-dependency-updates-on-steroids/\n  * By default, dep updates happen on sunday every week.\n  * The status of dependency updates can be viewed here if you have this repo permissions in github: https://app.renovatebot.com/dashboard#github/aicore/template-nodejs\n  * To edit rennovate options, edit the rennovate.json file in root, see https://docs.renovatebot.com/configuration-options/\n  Refer \n  \n# Code Guardian\nSeveral automated workflows that check code integrity are integrated into this template.\nThese include:\n1. GitHub actions that runs build/test/coverage flows when a contributor raises a pull request\n2. [Sonar cloud](https://sonarcloud.io/) integration using `.sonarcloud.properties`\n   1. In sonar cloud, enable Automatic analysis from `Administration\n      Analysis Method` for the first time ![image](https://user-images.githubusercontent.com/5336369/148695840-65585d04-5e59-450b-8794-54ca3c62b9fe.png)\n\n## IDE setup\nSonarLint is currently available as a free plugin for jetbrains, eclipse, vscode and visual studio IDEs.\nUse sonarLint plugin for webstorm or any of the available\nIDEs from this link before raising a pull request: https://www.sonarlint.org/ .\n\nSonarLint static code analysis checker is not yet available as a Brackets\nextension.\n\n## Internals\n### Testing framework: Mocha , assertion style: chai\n See https://mochajs.org/#getting-started on how to write tests\n Use chai for BDD style assertions (expect, should etc..). See move here: https://www.chaijs.com/guide/styles/#expect\n\n### Mocks and spies: sinon\n if you want to mock/spy on fn() for unit tests, use sinon. refer docs: https://sinonjs.org/\n\n### Note on coverage suite used here:\nwe use c8 for coverage https://github.com/bcoe/c8. Its reporting is based on nyc, so detailed docs can be found\n here: https://github.com/istanbuljs/nyc ; We didn't use nyc as it do not yet have ES module support\n see: https://github.com/digitalbazaar/bedrock-test/issues/16 . c8 is drop replacement for nyc coverage reporting tool\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faicore%2Felasticsearch-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faicore%2Felasticsearch-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faicore%2Felasticsearch-lib/lists"}