question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Different connect API

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
delvedorcommented, Sep 12, 2019

is there a pure TCP API with a long-lived connection?

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.

1reaction
delvedorcommented, Sep 11, 2019

I believe that my message above already contains the answer.

Furthermore, we can discuss if it makes sense to have one since there is never a “connect event”, because all the communications are done via HTTP and not TCP socket. You can use the ping API to see if the cluster is reachable before to start sending requests.

There is never a “connect” event since we are using HTTP to talk with Elasticsearch, and thus, having a “connect” event is useless.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use an API: Just the Basics 2022 | TechnologyAdvice
An API is how two computers talk to each other. The server has the data and sets the language while the client uses...
Read more >
Types Of API Calls & REST API Protocol - Stoplight
Open APIs. Open APIs, also known as external or public APIs, are available to developers and other users with minimal restrictions. · Internal...
Read more >
The Ultimate Guide to Accessing & Using APIs - HubSpot Blog
APIs are sets of definitions and protocols that allow software components to talk and interact with each other using a simple set of...
Read more >
What is an API Integration? (for non-technical people) - Tray.io
The term API integration refers to how two or more applications can be connected to each other via their APIs to perform some...
Read more >
Types of APIs and how to determine which to build - MuleSoft
System APIs: System APIs unlock data from core systems of record within an organization. · Process APIs: Process APIs interact with and shape...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found