1

I have a project that has a lot of information in the database, I have several tables that can contain names of people and I need to do a search by name, but I need that name to search in all fields of all tables, That's why I decided to use ElasticSearch but I don't know how to integrate it with NodeJs and Postgresql, all the tutorials that I find on the internet do not use postgres as a database, they use ElasticSearch as the database as well.

this way i initialize elasticsearch :

var elasticsearch = require('elasticsearch');

var client = new elasticsearch.Client({
hosts: [ 'http://localhost:9200']
});

client.ping({
requestTimeout: 30000,
}, function(error) {
if (error) {
console.error('Cannot connect to Elasticsearch.');
} else {
console.log('Connected to Elasticsearch was successful!');
}
});

and this way is how to i search in my postgres database :

await db.query('SELECT * FROM people WHERE name like '%Jhon%' OR comments like '%Jhon%'', (err, results) => {
        if (err) {
            console.log(err.stack);
            return res.send('Sorry an error ocurred');
        }

        var people = results.rows;


        console.log(people);


    })

How can i use ElasticSearch to search in my postgres database?

1
  • you need a process that will pull data from Postgres and put it into Elasticsearch. Commented Mar 6, 2020 at 9:20

1 Answer 1

1

You need to index all your data from Postgres to Elasticsearch to be able to search in elastic search. There are many ways to push data to elasticsearch. You can read some of the way here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.