Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda