-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide TS typings for Elasticsearch queries #27396
Comments
Pinging @elastic/kibana-platform |
The new elasticsearch-js client that @delvedor is working on has TypeScript support out of the box. We'll ultimately need to swap out our existing elasticsearch client for this one, so I think we'll be getting the types for free (to Kibana) here. |
Ah that's perfect. @delvedor We should make sure that those types are exported properly so you can use them for typing your own code, even in places you don't do immediately a request. @delvedor I would highly be interested if you could outline some of the typing ideas/plans for that library here if possible. |
Hello! I'm integrating the new client and kibana in #27051. If you like, we can organize a meeting where I show you the current work and the plans for the future. |
Oh nice, having types in the official JS client would be awesome! My prototype project was created by manually reading the documentation and then porting that over to TS, so something more official would be sweet. It looks like the new client uses |
The request typings can be generated, we generate the clients from the rest-api-spec, which is a json specification of every parameter that an API can accept. |
For instance, And That said, I assume the Java understands the types of everything at a deeper level, so there should be some way to extract. |
Closest we have is a dump of the .NET mappings of the API to TypeScript: https://github.com/elastic/elastic-client-generator/tree/master/specification/specs The automated exporter still needs some TLC e.g not all object inheritence gets persisted in typescript. Another reason work on this is stale is that the java server code is now moving from builders to pojo's for REST related classes. This is a much nicer source then the .NET mappings.and I want to jump on this to help get it into a state we can generate specs from in the new year. |
I've just opened a pr that adds typed request parameters to the new JavaScript client, feel free to give it a look! |
@jacobwgillespie thanks for your feedback here. Since you seem to work already with a TS version in your software, I would be highly interested if you have any feedback for the new official client. Hopefully we can leverage some of your experience with your client for that. |
After discussing with @delvedor we came to the following decisions:
I will close this issue for now, and will open an issue with |
The more we refactor to TypeScript the more places I see that it would be a benefit to have proper typings for Elasticsearch queries and responses. E.g. I was looking into getting some of the
AggConfig
orAggParam
infrastructure moved over to TypeScript, because we also have an awful amount ofcreateLegacyClass
(#21360) in that part.Since those write out aggregation I think it would be really helpful to be able to provide more typings than just
object
orany
, to prevent upcoming issues and ease maintenance of that code.I also think there might be other web projects out there, that could benefit from that, so I think it could make sense to publish that package to npm independently.
I currently see basically two ways to achieve that.
1) Do we have any formal description of the Elasticsearch API maintained by the Elasticsearch team? If so I think it would be worth looking into possibilities to write something that converts those to TS typings instead.
2) If that's not possible I think we need to build them ourselves. We could ideally use some existing work as a base for that, e.g. @jacobwgillespie has done an awesome job already writing (mot of the?) typings: https://github.com/jacobwgillespie/elastic-ts/tree/master/src/types This approach of course have the disadvantage that we need to update them manually, which will always be more work as if we can just auto generate them.
Even if we need to go down the second choice I think we should soon start looking into building them, so we can build our ES relevant code on top of that.
cc @stacey-gammon @lukeelmers
The text was updated successfully, but these errors were encountered: