# How to do float comparison

**URL:** <https://discuss.elastic.co/t/how-to-do-float-comparison/341881>\
**Category:** Logstash\
**Created:** [August 29, 2023, 1:03pm UTC](https://discuss.elastic.co/t/how-to-do-float-comparison/341881 "2023-08-29T13:03:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lostsoul352](https://avatars.discourse-cdn.com/v4/letter/l/d2c977/32.png) [@lostsoul352](https://discuss.elastic.co/u/lostsoul352)\
**Post date:** [August 29, 2023, 1:03pm UTC](https://discuss.elastic.co/t/how-to-do-float-comparison/341881/1 "2023-08-29T13:03:16Z")

</div>

I'm trying to drop events if the value of a float field is less than -90000

Here is a code snippet:

```auto
if [type] == "node_perf" {
         
         mutate {
             convert => { "nodeperf_value" => "float"}
         }

         if [nodeperf_value] < -90000 {
             drop { }
         }
}

```

This keeps giving me a syntax error. Is this because nodeperf\_value is a float? Is so how do I do this?

If I omit the if statement my code works, so it's definitely that which is causing the syntax error

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 29, 2023, 1:09pm UTC](https://discuss.elastic.co/t/how-to-do-float-comparison/341881/2 "2023-08-29T13:09:50Z")

</div>

> [@lostsoul352](#):
>
> This keeps giving me a syntax error.

What error are you getting?

---

<div class="post-metadata">

**Author:** ![lostsoul352](https://avatars.discourse-cdn.com/v4/letter/l/d2c977/32.png) [@lostsoul352](https://discuss.elastic.co/u/lostsoul352)\
**Post date:** [August 29, 2023, 1:13pm UTC](https://discuss.elastic.co/t/how-to-do-float-comparison/341881/3 "2023-08-29T13:13:10Z")

</div>

This

`[2023-08-29T09:11:34,169][ERROR][logstash.javapipeline][main] Pipeline worker error, the pipeline will be stopped {:pipeline_id=>"main", :error=>"", :exception=>Java::JavaLang::NullPointerException, :backtrace=>["org.logstash.config.ir.compiler.EventCondition$Compiler$UnexpectedTypeException.<init>(EventCondition.java:679)", "org.logstash.config.ir.compiler.EventCondition$Compiler.compare(EventCondition.java:453)", "org.logstash.config.ir.compiler.EventCondition$Compiler.lambda$compareFieldToConstant$11(EventCondition.java:444)", "org.logstash.config.ir.compiler.Utils.filterEvents(Utils.java:47)", "org.logstash.generated.CompiledDataset3.compute(Unknown Source)", "org.logstash.generated.CompiledDataset2.compute(Unknown Source)", "org.logstash.generated.CompiledDataset4.compute(Unknown Source)", "org.logstash.generated.CompiledDataset2.compute(Unknown Source)", "org.logstash.generated.CompiledDataset2.compute(Unknown Source)", "org.logstash.generated.CompiledDataset6.compute(Unknown Source)", "org.logstash.generated.CompiledDataset3.compute(Unknown Source)", "org.logstash.generated.CompiledDataset2.compute(Unknown Source)", "org.logstash.generated.CompiledDataset3.compute(Unknown Source)", "org.logstash.generated.CompiledDataset2.compute(Unknown Source)", "org.logstash.generated.CompiledDataset2.compute(Unknown Source)", "org.logstash.generated.CompiledDataset7.compute(Unknown Source)", "org.logstash.config.ir.CompiledPipeline$CompiledUnorderedExecution.compute(CompiledPipeline.java:329)", "org.logstash.config.ir.CompiledPipeline$CompiledUnorderedExecution.compute(CompiledPipeline.java:323)", "org.logstash.execution.WorkerLoop.run(WorkerLoop.java:83)", "java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)", "java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)", "java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)", "java.base/java.lang.reflect.Method.invoke(Method.java:566)", "org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(JavaMethod.java:441)", "org.jruby.javasupport.JavaMethod.invokeDirect(JavaMethod.java:305)", "org.jruby.java.invokers.InstanceMethodInvoker.call(InstanceMethodInvoker.java:32)", "usr.share.logstash.logstash_minus_core.lib.logstash.java_pipeline.RUBY$block$start_workers$5(/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:295)", "org.jruby.runtime.CompiledIRBlockBody.callDirect(CompiledIRBlockBody.java:138)", "org.jruby.runtime.IRBlockBody.call(IRBlockBody.java:58)", "org.jruby.runtime.IRBlockBody.call(IRBlockBody.java:52)", "org.jruby.runtime.Block.call(Block.java:139)", "org.jruby.RubyProc.call(RubyProc.java:318)", "org.jruby.internal.runtime.RubyRunnable.run(RubyRunnable.java:105)", "java.base/java.lang.Thread.run(Thread.java:834)"], :thread=>"#<Thread:0x2569c0ec sleep>"}`

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 29, 2023, 1:16pm UTC](https://discuss.elastic.co/t/how-to-do-float-comparison/341881/4 "2023-08-29T13:16:29Z")

</div>

> [@lostsoul352](#):
>
> :exception=\>Java::JavaLang::NullPointerException, :backtrace=\>["org.logstash.config.ir.compiler.EventCondition$Compiler$UnexpectedTypeException.(EventCondition.java:679)",

That is not a syntax error, it is a runtime exception. It occurs when you do a numerical comparison on a field that does not exist. See [this](https://discuss.elastic.co/t/comparing-number-in-conditionnal-event-treatement/217043/5) thread.

Try changing your conditional to

```
if [nodeperf_value] and [nodeperf_value] < -90000 {

```

---

<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:** [September 26, 2023, 1:17pm UTC](https://discuss.elastic.co/t/how-to-do-float-comparison/341881/5 "2023-09-26T13:17:14Z")

</div>

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