Using json-input and unable to access the unique count result

Hello,
I am running a line graph with a unique counter over time. Simple.
When I use a json input to show "{ "script": "_value - 1 " }" I get the error Courier Fetch: 10 of 30 shards failed.
Note that I always use json input like this on fields, but this time it's a unique count.
I found this in the log, but it doesn't make sense, I am applying "-1" on the result which is a count, which is a number. am I not? and if not - how do I apply "-1" on the result of the unique count?

Caused by: java.lang.ClassCastException: Cannot apply [-] operation to types [java.lang.String] and [java.lang.Integer].

More of the logs just in case you need it:

[2018-03-22T21:35:47,078][DEBUG][o.e.a.s.TransportSearchAction] [9sPmWfk] [unifieddxcvpc][3], node[9sPmWfkZQw64EnezpAaHBw], [P], s[STARTED], a[id=kJwYy_maSDuSqmw
8wD5o9Q]: Failed to execute [SearchRequest{searchType=QUERY_THEN_FETCH, indices=[unified1, unified2, unified2a, unified3, unified4, un
ifiedd5], indicesOptions=IndicesOptions[id=39, ignore_unavailable=true, allow_no_indices=true, expand_wildcards_open=true, expand_wildcards_closed=false, all
ow_aliases_to_multiple_indices=true, forbid_closed_indices=true, ignore_aliases=false], types=[], routing='null', preference='1521661353677', requestCache=null,
scroll=null, maxConcurrentShardRequests=5, batchedReduceSize=512, preFilterShardSize=64, source={"size":0,"query":{"bool":{"must":[{"match_all":{"boost":1.0}},{"
range":{"datetime":{"from":1521164149553,"to":1521768949553,"include_lower":true,"include_upper":true,"format":"epoch_millis","boost":1.0}}}],"adjust_pure_negati
ve":true,"boost":1.0}},"_source":{"includes":[],"excludes":[]},"stored_fields":"*","docvalue_fields":["@timestamp","datetime","installation_date"],"script_fields
":{},"aggregations":{"2":{"date_histogram":{"field":"datetime","time_zone":"America/New_York","interval":"2d","offset":0,"order":{"_key":"asc"},"keyed":false,"mi
n_doc_count":1},"aggregations":{"1":{"avg":{"field":"clus_vmem_mem_ratio","script":{"source":"_value * 100 ","lang":"painless"}}},"3":{"avg":{"field":"clus_vcpu_
cpu_ratio","script":{"source":"_value * 100 ","lang":"painless"}}},"4":{"cardinality":{"field":"pm_uuid.keyword","script":{"source":"_value - 2 ","lang":"painles
s"}}}}}}}}] lastShard [true]
org.elasticsearch.transport.RemoteTransportException: [9sPmWfk][10.16.172.171:9300][indices:data/read/search[phase/query]]
Caused by: org.elasticsearch.search.query.QueryPhaseExecutionException: Query Failed [Failed to execute main query]
        at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:290) ~[elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:107) ~[elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.search.SearchService.loadOrExecuteQueryPhase(SearchService.java:307) ~[elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:340) ~[elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.search.SearchService$2.onResponse(SearchService.java:316) ~[elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.search.SearchService$2.onResponse(SearchService.java:312) ~[elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.search.SearchService$3.doRun(SearchService.java:1002) ~[elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:672) [elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:41) [elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-6.2.2.jar:6.2.2]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_161]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_161]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_161]
Caused by: org.elasticsearch.script.ScriptException: runtime error
        at org.elasticsearch.painless.PainlessScript.convertToScriptException(PainlessScript.java:101) ~[?:?]
        at org.elasticsearch.painless.PainlessScript$Script.execute(_value - 2 :1) ~[?:?]
        at org.elasticsearch.painless.ScriptImpl.run(ScriptImpl.java:105) ~[?:?]
        at org.elasticsearch.search.aggregations.support.ValuesSource$WithScript$BytesValues.advanceExact(ValuesSource.java:464) ~[elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityAggregator$MurmurHash3Values$Bytes.advanceExact(CardinalityAggregator.java:388) ~[elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityAggregator$DirectCollector.collect(CardinalityAggregator.java:196) ~[elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.search.aggregations.LeafBucketCollector$2.collect(LeafBucketCollector.java:67) ~[elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.search.aggregations.bucket.BucketsAggregator.collectExistingBucket(BucketsAggregator.java:84) ~[elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregator$1.collect(DateHistogramAggregator.java:116) ~[elasticsearch-6.2.2.jar:6.2.2]
.
.
.
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[?:1.8.0_161]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[?:1.8.0_161]
        at java.lang.Thread.run(Thread.java:748) ~[?:1.8.0_161]
Caused by: java.lang.ClassCastException: Cannot apply [-] operation to types [java.lang.String] and [java.lang.Integer].

I don't know painless too well, but;

Might suggest that the syntax you are using is not correct?

So .. what would be the correct way to get the numeric value of a unique count field ?

Just edited the message and moved to the correct subject (kibana)

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.