java.sql.SQLException: Validation failed for <field_name>: 'null' cannot be cast to type double
<p>I am using logstash to create a pipeline from elasticsearch to crate.io. Below is the config.</p>

<pre><code>input{
 elasticsearch {
   hosts =&gt; "&lt;host_name&gt;:9200"
   index =&gt; "index1"
   query =&gt; '{ "size":10,"query": {"match_all": {} } }'
   }
}
filter{
    if!([bench_pose][M_Body_t]) {
            mutate{
                    add_field =&gt; {"[bench_pose][M_Body_t]" =&gt; null}
            }
    }
    if!([bench_pose][M_Jaw_t]) {
            mutate{
                    add_field =&gt; {"[bench_pose][M_Jaw_t]" =&gt; null}
            }
    }
}
output{
 jdbc {
       driver_class =&gt; "io.crate.client.jdbc.CrateDriver"
       driver_auto_commit =&gt; false
       driver_jar_path =&gt; "/etc/crate/crate-jdbc-standalone-1.12.3.jar"
       connection_string =&gt; "crate://&lt;host_ip&gt;:4300"
       statement =&gt; ["INSERT INTO table_name(path,bench_pose_m_Body_t,bench_pose_m_jaw_t) VALUES(?,?,?)",'path','%{[bench_pose][M_Body_t]}','%{[bench_pose][M_Jaw_t]}']
   }
}
</code></pre>

<p>The source has a field 'bench_pose' which is of OBJECT datatype, and the fields M_Body_t and M_Jaw_t under bench_pose are of type DOUBLE. These fields are NULLable in source and destination. This field has null values in few documents in the source. Even though the destination table has NULLable fields, when the insert statement encounters a document with null value, throws the below error.</p>

<pre><code>JDBC - Exception. Not retrying. {:exception=&gt;java.sql.SQLException: Validation failed for bench_pose_m_body_t: 'null' cannot be cast to type double  
</code></pre>

<p>If I remove the filter plugin, it throws an error as below.</p>

<pre><code>JDBC - Exception. Not retrying. {:exception=&gt;java.sql.SQLException: Validation failed for bench_pose_m_body_t: '%{[bench_pose][M_Body_t]}' cannot be cast to type double
</code></pre>

<p>If I hard code null value in an insert and run the query on crate sql, it executes correctly.
How do I parse null values in these fields in logstash?</p>