ElasticSearch: Adding multiple fields in a document

0

I need to add different fields and merge them into a single field in ElasticSearch search in POST mode in>), but I only know the form that distinctly adds each field, as follows:

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

I need to join the sum of the three aggregations above. That's it.

Thanks for the help!

    
asked by anonymous 24.06.2017 / 00:03

1 answer

1

Thiago, you can simply add one more item in your aggregation that adds the results. Just have to be careful to use the correct notation of ES.

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']" } } } }

    
26.06.2017 / 19:07