Facets and sums for value_script


(kevins) #1

My documents have a field called "debit" and SOME of them have a field
called "credit".

I am interested in returning a facet that aggregates the debit + credit

I can do this for one or the other, but not both. Here is the query that I
am using:

{
"query" : {
"match_all" : { }
},
"sort" : [ { "credit" : {"order" : "desc"} } ],
"facets" : {
"debit_stats" : {
"terms_stats" : {
"key_field" : "origin",
"value_field" : "credit",
"order": "term"
}
}
}
, size: 0
}

I have tried to use a value_script instead of a value_field like this:

"value_script" : "doc['credit'].value + doc['debit'].value",

Which gives me an error,

org.elasticsearch.index.fielddata.ScriptDocValues$Empty

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/971f422a-78bd-4b01-ab99-d893ed00104b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #2