Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
Getting only the insides of the source from the elastic search query

What im trying to do is to get only the source from the elastic search query in order to skip the processing on the javascript, so i could squize some more performance gains.Is it possible to do so?

So here is what i currenly do, i just get the data from the elastic search and iterate every one of those objects in order to construct an array that only contains the what's inside of _source:

const { body } = await this.elsticSearchService.search<any>({
 index: this.configService.get('ELASTICSEARCH_INDEX'),
 body: {
 query: {
    match_all: {},
    },
    size: 10000,
  },
});

const hits = body.hits.hits;

return hits.map((item: any) => item._source);

So my question is, is there a way to only get the _source from the elastic search, in order to skip the processing on the JavaScript? So the object returned from the elastic search would look like this

[
0:{ "key": "value"}, // key,value from _source object
1:{ "key": "value"}, // key,value from _source object
2:{ "key": "value"}, // key,value from _source object
]

so without all of the other fields like hits, took etc...

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It's not possible to change the structure of the response you get from the search call.

However, what you can do is to specify filter_path so you only get the _source content in the response and you wouldn't need to process it since you know you only have _source content

const { body } = await this.elsticSearchService.search<any>({
 index: this.configService.get('ELASTICSEARCH_INDEX'),
 filter_path: '**._source',         <--- add this line
 body: {
 query: {
    match_all: {},
    },
    size: 10000,
  },
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!