# ctx.containksKey is not working in 7.6 version

**URL:** <https://discuss.elastic.co/t/ctx-containkskey-is-not-working-in-7-6-version/244846>\
**Category:** Elasticsearch\
**Created:** [August 13, 2020, 9:52am UTC](https://discuss.elastic.co/t/ctx-containkskey-is-not-working-in-7-6-version/244846 "2020-08-13T09:52:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anjilinga](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anjilinga/32/86010_2.png) [@anjilinga](https://discuss.elastic.co/u/anjilinga)\
**Post date:** [August 13, 2020, 9:52am UTC](https://discuss.elastic.co/t/ctx-containkskey-is-not-working-in-7-6-version/244846/1 "2020-08-13T09:52:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 13, 2020, 12:04pm UTC](https://discuss.elastic.co/t/ctx-containkskey-is-not-working-in-7-6-version/244846/2 "2020-08-13T12:04:19Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![anjilinga](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anjilinga/32/86010_2.png) [@anjilinga](https://discuss.elastic.co/u/anjilinga)\
**Post date:** [August 14, 2020, 9:15am UTC](https://discuss.elastic.co/t/ctx-containkskey-is-not-working-in-7-6-version/244846/3 "2020-08-14T09:15:02Z")

</div>

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"  
}  
}  
]

}

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 14, 2020, 10:25am UTC](https://discuss.elastic.co/t/ctx-containkskey-is-not-working-in-7-6-version/244846/4 "2020-08-14T10:25:24Z")

</div>

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

```auto
{
  "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

---

<div class="post-metadata">

**Author:** ![anjilinga](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anjilinga/32/86010_2.png) [@anjilinga](https://discuss.elastic.co/u/anjilinga)\
**Post date:** [August 16, 2020, 6:43pm UTC](https://discuss.elastic.co/t/ctx-containkskey-is-not-working-in-7-6-version/244846/5 "2020-08-16T18:43:09Z")

</div>

Sorry for the complex message format.

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

---

<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 13, 2020, 6:43pm UTC](https://discuss.elastic.co/t/ctx-containkskey-is-not-working-in-7-6-version/244846/6 "2020-09-13T18:43:21Z")

</div>

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