# Search\_phase\_execution\_exception Caused by: script\_exception: compile error, caused by: "compile error,cannot resolve symbol \[B\]"

**URL:** <https://discuss.elastic.co/t/search-phase-execution-exception-caused-by-script-exception-compile-error-caused-by-compile-error-cannot-resolve-symbol-b/342462>\
**Category:** Kibana\
**Tags:** elastic-stack-alerting\
**Created:** [September 6, 2023, 4:35pm UTC](https://discuss.elastic.co/t/search-phase-execution-exception-caused-by-script-exception-compile-error-caused-by-compile-error-cannot-resolve-symbol-b/342462 "2023-09-06T16:35:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gelinski](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gelinski/32/142412_2.png) [@Gelinski](https://discuss.elastic.co/u/Gelinski)\
**Post date:** [September 6, 2023, 4:35pm UTC](https://discuss.elastic.co/t/search-phase-execution-exception-caused-by-script-exception-compile-error-caused-by-compile-error-cannot-resolve-symbol-b/342462/1 "2023-09-06T16:35:09Z")

</div>

Hello folks,

I am trying to create an Alert Rule of 'Metric threshold' type where I am using the 'custom equation' condition option to calculate a percentage.

The details of the rule are bellow:

**Condition**  
When custom equation is above or equal to 0.05

**Aggregations**  
Aggregation A = Document count of query filter for field A  
Aggregation B = Document count of query filter for field B

**Equation**  
A/(A+B)

Even with A and B returning valid values, I got the following error at rule execution:

search\_phase\_execution\_exception Caused by: script\_exception: compile error, caused by: "compile error,cannot resolve symbol [B]"

I did a simple test changing the equation to A+B and it works.

Could this be a bug?

Thanks,  
Matheus

---

<div class="post-metadata">

**Author:** ![simianhacker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simianhacker/32/3383_2.png) [@simianhacker](https://discuss.elastic.co/u/simianhacker)\
**Post date:** [September 14, 2023, 3:31pm UTC](https://discuss.elastic.co/t/search-phase-execution-exception-caused-by-script-exception-compile-error-caused-by-compile-error-cannot-resolve-symbol-b/342462/2 "2023-09-14T15:31:05Z")

</div>

This is a bug... the work around would be to do:

**Aggregations**  
Aggregation A = Document count of query filter for field A  
Aggregation B = Document count of query filter for field B  
Aggregation C = Document count of query filter for field A

**Equation**  
A/(C+B)

> <https://github.com/elastic/kibana/issues/166476>
>
> \*\*Kibana version:\*\*
> 
> 8.7+
> 
> \*\*Original install method (e.g. download page, yu…m, from source, etc.):\*\*
> 
> ANY
> 
> \*\*Describe the bug:\*\*
> 
> When you use the same variable twice in the custom equation, the rule and preview throws a 500.
> 
> \*\*Steps to reproduce:\*\*
> 1. Create a Metric Threshold rule with a custom equation
> 2. Add 2 metrics, \`A\` and \`B\`
> 3. Change the equation to \`A / (A + B)\`
> 
> \*\*Expected behavior:\*\*
> 
> It should work correctly.
> 
> \*\*Additional context:\*\*
> 
> We need to change \`acc.replace\` to \`acc.replaceAll\` on this line:
> 
> https://github.com/elastic/kibana/blob/6ab7ec48cfd962b573e6f3f7ff9f4b12779df413/x-pack/plugins/infra/server/lib/create\_custom\_metrics\_aggregations.ts#L77

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 12, 2023, 3:31pm UTC](https://discuss.elastic.co/t/search-phase-execution-exception-caused-by-script-exception-compile-error-caused-by-compile-error-cannot-resolve-symbol-b/342462/3 "2023-10-12T15:31:25Z")

</div>

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