elasticsearch-postgresql-data-indexer
is a Node.js application that parses data from a PostgreSQL table and indexes it into an Elasticsearch index. This tool is useful for synchronizing data between a PostgreSQL database and Elasticsearch, enabling efficient search capabilities on the data.
- Parses data from a specified PostgreSQL table
- Indexes data into an Elasticsearch index
- Built with TypeScript for type safety
- Uses Express.js for routing
- Includes a route to trigger the indexing process
- Node.js (v14.x or later)
- PostgreSQL database
- Elasticsearch (v7.x or later)
-
Clone the repository:
git clone https://github.com/skanderbenali/elasticsearch-postgresql-data-indexer.git cd elasticsearch-postgresql-data-indexer
-
Install the dependencies:
npm install
-
Create an
app.env
file in the root of the project with the following content:PORT=3000 DB_USER=postgres DB=database DB_PASS=password DB_HOST=localhost DB_PORT=5432 DB_MAX_CLIENTS=20 DB_IDLE_TIMEOUT_MS=30000 ELK_HOST=https://localhost:9200 ELK_PORT=9200 ELK_USERNAME=elastic ELK_PASSWORD=password ELK_INDEX=indexname ELK_CA_FILE_PATH=ca_path
-
Create a
.env
file in the root of the project with the following content:######################################## #############ELK VARS################### ######################################## # Version of Elastic products STACK_VERSION= # Set to 'basic' or 'trial' to automatically start the 30-day trial LICENSE= # Password for the 'elastic' user (at least 6 characters) ELASTIC_PASSWORD= # Password for the 'kibana_system' user (at least 6 characters) KIBANA_PASSWORD= # Set the cluster name CLUSTER_NAME= # Increase or decrease based on the available host memory (in bytes) MEM_LIMIT= # Log ES_LOG_LEVEL=
-
Build the project:
npm run build
-
Start the application:
npm start
-
Use the
/indexData
route to trigger the indexing process. For example, if you are running the application locally, you can trigger the route using curl or a web browser:curl http://localhost:3000/indexData
src/
: Source code for the applicationbuild/
: Compiled JavaScript filespackage.json
: Project metadata and dependenciesapp.env
: Application environment configuration.env
: Environment configuration for Elasticsearch stack.gitignore
: Specifies which files and directories to ignore in the repository
npm run build
: Compiles the TypeScript code into JavaScriptnpm run lint
: Runs ESLint to check for code quality issuesnpm run start
: Lints the code, compiles the TypeScript, and starts the applicationnpm run test
: Runs tests using Jest and outputs a coverage report
@elastic/elasticsearch
: Elasticsearch client for Node.jsasync
: Utility module for asynchronous programmingbody-parser
: Middleware for parsing JSON and URL-encoded request bodiescompromise
: Natural language processing librarydotenv
: Loads environment variables from a .env fileexpress
: Web framework for Node.jsioredis
: Redis client for Node.jspg
: PostgreSQL client for Node.jspg-promise
: Promises-based PostgreSQL client for Node.jswinston
: Logging library
@types/...
: TypeScript definitions for various modules@typescript-eslint/...
: ESLint plugin and parser for TypeScripteslint
: JavaScript linterjest
: Testing frameworkprettier
: Code formatterts-jest
: Jest transformer for TypeScriptts-node
: TypeScript execution environment for Node.jstypescript
: TypeScript compiler
This project is licensed under the SkanderBenali License.
Skander Benali