Different connect API
See original GitHub issueI am really confused…there is a new NPM project @elastic/elasticsearch - that code should just go in a new repo - why not just create a new repo elasticsearch.ts or elasticsearch.js and link to that from this one?
Anyway, regarding the new codebase, I am really happy to see that it’s written in TypeScript, that’s good news, but I have this problem/question:
import * as es from '@elastic/elasticsearch';
const client = new es.Client({node: 'http://ec2-xx-237-xx-107.us-west-2.compute.amazonaws.com:9200'});
client.once('connect', () => {
run(); // kiss
});
const run = () => {
client.indices.create({
index: 'foo'
})
.then(v => {
console.log(v);
});
};
it seems to connect, but the ‘connect’ event doesn’t fire. This would be obvious feature that seems to be missing. However, if it’s not too late, I recommend this API design instead:
import * as es from '@elastic/elasticsearch';
const client = new es.Client({node: 'http://ec2-xx-237-xx-107.us-west-2.compute.amazonaws.com:9200'});
const p = client.connect();
p.then(c => {
client.indices.create({
index: 'foo'
})
.then(v => {
console.log(v);
});
});
using promises for connections like that is a good use case for promises. So the feature request here is to fire the ‘connect’ even upon a connection, and/or use a method called “connect()” which will return a promise.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Nope, but the client uses a Keep-Alive agent to avoid wasting time in multiple handshakings. If needed, you can configure it with the
agent
option.I believe that my message above already contains the answer.
There is never a “connect” event since we are using HTTP to talk with Elasticsearch, and thus, having a “connect” event is useless.