Incorrect form of @types/elasticsearch SearchResponse

Whenever I utilize the ElasticsearchService from @nestjs/elasticsearch, the response does not align with the type SearchResponse from @types/elasticsearch. The issue is that SearchResponse is supposed to be an object, but I actually receive an array containing both the SearchResponse object and an HTTP Status Code. Does anyone know how to disable this feature?

For instance:

[
  {
    ...,
    "aggregations": {
      "backendVersions": {
        "doc_count_error_upper_bound": 0,
        "sum_other_doc_count": 0,
        "buckets": [
          {
            "key": "1.0.0",
            "doc_count": 1
          }
        ]
      }
    }
  },
  200
]

Answer №1

The ElasticsearchService provided in @nestjs/elasticsearch wraps the Elasticsearch client with bindNodeCallback, as detailed in the documentation.

For example:

client.search({
  index: 'my-index',
  body: { foo: 'bar' }
}, (err, body, statusCode, headers) => {
  if (err) console.log(err)
})

This will be converted into an observable that emits a value with the arguments from the callback, excluding the error, in an array.

service.search({
  index: 'my-index',
  body: { foo: 'bar' }
}).subscribe(value => {
  console.log(value); // [body, statusCode, headers]
});

You cannot disable this functionality, but you have the option to use the Elasticsearch client directly by calling getClient():

const searchResponse = await service.getClient().search({
  index: 'my-index',
  body: { foo: 'bar' }
});

Additionally, please note that there may be breaking changes in @elastic/elasticsearch [7.x]:

client.search({
  index: 'my-index',
  body: { foo: 'bar' }
}, (err, { body, statusCode, headers, warnings }) => {
  if (err) console.log(err)
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unlocking the accordion feature in Ionic 3 form: A step-by-step guide

I am currently working on a search form and want to incorporate it within an accordion so that users can simply click to expand the form. Below is the code snippet: TS. buildForm(): void { this.form = this.fb.group({ username: new FormControl(& ...

Troubles encountered while deploying NestJS and Socket.IO application on Heroku due to PORT issue

Recently, I developed an application with NestJS and Socket.IO. To enable it to listen on a different port than the default one, I implemented a gateway. Surprisingly, everything runs smoothly when testing it on my localhost. But, upon deployment to Heroku ...

Securing Routes in React-Ionic app with Firebase Authentication Context

Currently, I'm in the process of setting up Firebase authentication within a React-Ionic application. I have implemented some protected routes that require authentication to access them. While the setup is partially working, there are still some issue ...

Ensuring data integrity by validating incoming data with TypeScript and Angular 2

What is the best approach to validate data received from the server using AJAX or in a child component using the @input decorator in Angular2+ applications? In my current project, I utilize interfaces for this purpose, however they do not entirely valida ...

Obtain the correct context within the callback

Whenever I attempt to invoke a function within a callback and utilize the class context(this), I face an issue where the callback function doesn't carry any context. The value of this ends up being undefined. I have experimented with using bind(self), ...

The Authorization header in POST and PATCH fetch requests is stripped by Typescript

I have developed an API in C# that utilizes JWT tokens for authorization. On the frontend, I store these tokens in local storage and retrieve them when making a request. GET or DELETE requests work seamlessly, as I can verify through console.log() that t ...

Is emitting a side effect event acceptable within an RxJS pipe?

Currently, I am utilizing RxJS within the context of an Angular application. Within my service, there is functionality to reinitialize the entire application with different settings as needed. @Injectable() class BootstrapService{ public initApplicatio ...

typescript error indicating a missing property that is expected to exist

I am struggling to comprehend the reason behind this error message. Property 'message' does not exist on type '{ username: string; } | { message: string; }'. The following is a snippet of the relevant code: // types.ts type LoginMess ...

Issue encountered during project upload due to deployment error

Make sure to wrap useSearchParams() in a suspense boundary on the "/auth-callback" page. For more information, check out https://nextjs.org/docs/messages/missing-suspense-with-csr-bailout import React, { useEffect } from 'react'; import { useRou ...

How do I import NPM modules in Angular 5 without using @types?

Currently experimenting with Angular 5 and beginning a project from angular-cli. I am interested in incorporating a NPM module called J2M (https://github.com/kylefarris/J2M). During my research, I came across these two commands: npm install j2m --save npm ...

What is the best way to refresh the script located within the head tag of an index.html file in an Angular

I've been looking for solutions, but I can't seem to find one. In my index.html file, I've placed some script within the head tag (even above the </body> tag) and included a $(document).ready function. The issue I'm facing is th ...

Tips for using useState to update only the element that was clicked:

When I click the button to add a step to a chapter, it's adding a step to all chapters instead of just one. What mistake am I making? const example_chapters = [ { id: 1, title: 'Chapter 1'}, { id: 2, title: 'Chapter 2'}, ...

What is the significance of using interfaces in parentheses when assigning typescript types?

These are the 2 interfaces I currently have export interface Contact { first_name: string; last_name: string; emails?: (EmailsEntity)[] | null; company: string; job_title: string; } export interface EmailsEntity { email: string; label: strin ...

Error: Missing provider for HttpTestingController in Angular testing context

Encountered an error while attempting to test my service, despite following the steps outlined in this tutorial NullInjectorError: No provider for HttpTestingController! error properties: Object({ ngTempTokenPath: null, ngTokenPath: [ &a ...

Tips for effectively sharing custom validators across different modules

After creating a password validator based on a tutorial, I attempted to use it on multiple forms within different parts of my application. However, I encountered an error stating: Type PasswordValidator is part of the declarations of 2 modules: SignupMod ...

Using react-confetti to create numerous confetti effects simultaneously on a single webpage

I'm looking to showcase multiple confetti effects using the react-confetti library on a single page. However, every attempt to do so in my component seems to only display the confetti effect on the last element, rather than all of them. The canvas fo ...

What is the best way to utilize *ngSwitchWhen in a TypeScript environment?

I am currently working with Ionic2 and Angular2 and encountering an issue while trying to implement a segment using ngSwitchWhen. Unfortunately, the functionality is not working as expected and I am receiving an error message. How can I resolve this issue ...

Issue encountered with Ionic and ssh2: process.binding is not supported

I am currently delving into the world of Ionic and experimenting with creating a basic application that utilizes SSH2 to establish an ssh connection between the app and a server. Here is a breakdown of the steps I took to encounter the issue: Steps to Rep ...

Does the ViewContainerRef for the Directive determine the element on which the directive is declared?

When a directive is constructor-injected with a ViewContainerRef, is the ViewContainerRef referring to the element on which the directive is declared? For instance, <p [someDirective]="value"></p> Consider this scenario with constructor injec ...

What prevents `console.log` from working within a button click event?

Why is this not functioning correctly? <button (click)="console.log('ok');">Display Details</button> The error message reads: Cannot read property 'log' of undefined However, a console.log statement in the class construc ...