I've been trying to find a way to return a document count in painless, but I can't find the answer anywhere. Is there any way to do this? I need to use this value as part of a painless script but I can't find a way to do it. Thanks for any help provided!
The scope of a scripted field is limited to the current document, so you can't really get a count as that is a bucket related aggregation. There are some ways to work with previous aggregations but that is part of the pipeline aggregations. Can you let us know what you were trying to accomplish with the count in painless and maybe we can offer you a workaround for this.
Hi Marius,
So we have fields in our documents such as "outcome" which contain a string value, e.g. "AUTO". I want to be able to find the percentage of documents in the index that have "AUTO" as the value for "outcome". Is there an easy way to do this? I can't find a way to display this in a graph without some sort of script field? Ideally I'd have a data table full of percentage values like this. Is there anything you can think of that might help?
Thanks,
Andrew.
There is a way to do this without using scripted fields:
Create an Area Chart, with a date histogram on the x-axis and a Split Series with a Filters aggregation with the following filters:
outcome:AUTO
and -outcome:AUTO
where the -
means NOT
.
On the metrics side, you need to set it to "Cumulative Sum of Count" which is a pipeline aggregation that will replace what you wanted to create with scripted fields.
Then you change the mode for the Y-axis from Normal to Percentage if you want to see percentages instead of absolute values for this.
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.