ctx.containksKey is not working in 7.6 version

Hi
I am using ctx.containsKey in ingestpipeline, it is not working in 7.6.2 vesrsion. but it is working in 7.8 version. can you please help here is it expected behaviour in 7.6 versions

please provide a fully reproducible example including a sample document and an ingest pipeline that includes your script processor. Thanks.

Best would be an execute ingest pipeline that includes a sample document and the pipeline in a single request!

Hi
Below is the input document columns mapping in logstash.
["prometheus.metrics.node_time_seconds","prometheus.metrics.node_boot_time_seconds","prometheus.metrics.node_memory_MemAvailable_bytes","prometheus.labels.mode","prometheus.metrics.node_load1"]
below are the values for the ablove columns,
20,15,,,
,15,25,,30
20,,20,35,
20,15,10,20,25
20,15,,20,25
20,15,10,20,

source index is having the values of input column mentioned above with the name servicename.
prometheus.metrics.node_time_seconds,esp
prometheus.metrics.node_boot_time_seconds,esp
prometheus.metrics.node_memory_MemAvailable_bytes,esp
prometheus.metrics.node_memory_MemTotal_bytes,esp
prometheus.metrics.node_network_receive_bytes_total,esp
The average network traffic received, per second,esp
prometheus.metrics.node_network_transmit_bytes_total,esp
prometheus.metrics.node_memory_MemFree_bytes,esp
prometheus.metrics.node_memory_Cached_bytes,esp
prometheus.metrics.node_memory_Buffers_bytes,esp
prometheus.metrics.node_load1,esp
prometheus.metrics.node_load5,esp
prometheus.metrics.node_load15,esp
prometheus.metrics.node_cpu_seconds_total,esp
prometheus.metrics.node_filesystem_avail_bytes,esp
prometheus.metrics.node_filesystem_size_bytes,esp
prometheus.metrics.node_cpu_seconds_total,esp
prometheus.labels.mode,esp
prometheus.metrics.node_memory_MemFree_bytes,esp

Below is the injest pipeline configuration.

PUT /_ingest/pipeline/node_lookup
{
"description" : "Enrich Node information",
"processors" : [
{"set": {
"field": "lob",
"value": "esp"
}},
{ "enrich": {
"policy_name": "enrich-service-policy",
"field": "lob",
"target_field": "srvc",
"max_matches": 100,
"if": "ctx.lob != null"
}
},{
"script": {
"lang":"painless",
"source": """
def srvclist =;

	int len=ctx.srvc.length;
	
    if (len > 0){
      
	for(int i=0;i<len-1;i++){
	if (ctx.containsKey('agent.id')){
	  srvclist.add(ctx.srvc[i]);
	  
	}
    }
    }
   ctx.srvcnew =srvclist;
        """
        , "if": "ctx.srvc != null"
      }
    }
     
           ]
,

"on_failure" : [
{
"set" : {
"field" : "error",
"value" : "Failed enrichment"
}
}
]

}

please take your time to properly format your posts, this is nearly impossible to read. Thanks!

I suppose that agent.id is actually in the structure of

{
  "agent" : {
    "id" : ...
  }
}

this means you need to check for the key agent and then cast the ctx.get('agent') to a map and check for that key

Sorry for the complex message format.

Can you please update me that conains.Key will work in 7.6 version also ?

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