Skip to content
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

Add typescript generics for search results response #45

Open
jenseo opened this issue Sep 6, 2023 · 1 comment
Open

Add typescript generics for search results response #45

jenseo opened this issue Sep 6, 2023 · 1 comment

Comments

@jenseo
Copy link

jenseo commented Sep 6, 2023

🚀 Feature Proposal

Implement the same type of TypeScript generics for search responses as can be seen in the elastic javascript client, where it's possible to define the results type of the response.

Motivation

At the moment, the type definition of the results part of a search response is defined as results: Array<{}>;. Comparing with the elasticsearch js client, which we sadly doesn't seem to be able to use since we use the enterprise app search. The way they have solved this looks like a better approach in my opinion.

They seem to be using the Elasticsearch specification repo for this, at least according to their docs.

For context, we are utilizing the node js client in our project.

Example

interface Document {
  character: string
  quote: string
}

const result= await client.search<Document>({
    index: 'game-of-thrones',
    query: {
      match: { quote: 'winter' }
    }
  })

The above would return the same response type as is currently implemented, but also with the results array typed with the Document interface.

@servefast-cto
Copy link

This would be great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants