Would this work?
.env:
ELASTIC_SEARCH_URI=http://localhost:9200/example-dev
The docs just say to use ELASTIC_SEARCH_URI=http://localhost:9200/
but I have two different apps on same dedicated server using elasticsearch. I want to specify a unique database for each app.
const es = new ElasticsearchClient({
node: "http://localhost:9200",
/*
auth: {
username: 'elastic',
password: 'password'
}
*/
});
CodePudding user response:
If you want multiple instances of Elasticsearch you can create 2 different containers, one will listen to :9200
and the other :9201
for example.
If what you mean by specifying database
is different index. Then you can encapsulate the necessary function to your needs.
// search func in app 1
const esSearch = (body) => {
const response = await es.search({
target: "my-app1",
body,
});
}
// search func in app 2
const esSearch = (body) => {
const response = await es.search({
target: "my-app2",
body,
});
}
There is no specifying the database because Elasticsearch itself is a single database. You can create different indices for different data.
CodePudding user response:
You can use below code for two different apps:
APP1
Lets consider datsource name for APP1 is example-dev
const es = new ElasticsearchClient({
node: "http://localhost:9200",
/*
auth: {
username: 'elastic',
password: 'password'
}
*/
});
const result = await es.search({
index: 'example-dev',
query: {
match: {
quote: 'winter'
}
}
})
APP2
Lets consider datsource name for APP2 is example-dev-app2
const es = new ElasticsearchClient({
node: "http://localhost:9200",
/*
auth: {
username: 'elastic',
password: 'password'
}
*/
});
const result = await es.search({
index: 'example-dev-app2',
query: {
match: {
quote: 'winter'
}
}
})