Elasticsearch: Add multiple fields of a document

Asked

Viewed 218 times

0

I need to add fields different and join them in a single field on the return of the Elasticsearch (search in POST mode), but I only know the way distinctly sum each field, as follows:

"aggs" : {
    "soma1" : { "sum" : { "field" : "consulta.campo.quantidade" } },
    "soma2" : { "sum" : { "field" : "solicitacao.campo.quantidade" } },
    "soma3" : { "sum" : { "field" : "anexo.campo.quantidade" } }
}

Precise join together the sum of three aggregations up. That’s it.

Thanks for the help!

1 answer

1


Thiago, Voce can simply add one more item in its aggregation that sums the results. Just take care to use the correct ES rating.

In your example to add the 3 fields would look like this:

"aggs" : { "consultaServicosQuantidadeAprovada" : { "sum" : { "field" : "consulta.servicos.quantidadeAprovada" } }, "solicitacaoServicosQuantidadeAprovada" : { "sum" : { "field" : "solicitacao.servicos.quantidadeAprovada" } }, "anexoServicosQuantidadeAprovada" : { "sum" : { "field" : "anexo.servicos.quantidadeAprovada" } }, "totalGeral" : { "sum" : { "script" : { "inline": "doc['consulta.servicos.quantidadeAprovada'] + doc['solicitacao.servicos.quantidadeAprovada'] + doc['anexo.servicos.quantidadeAprovada']" } } } }

  • This was the field I needed. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.