# Help with aggregation using script fields

**URL:** <https://discuss.elastic.co/t/help-with-aggregation-using-script-fields/50781>\
**Category:** Elasticsearch\
**Created:** [May 23, 2016, 11:07pm UTC](https://discuss.elastic.co/t/help-with-aggregation-using-script-fields/50781 "2016-05-23T23:07:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eugeniocesar](https://avatars.discourse-cdn.com/v4/letter/e/cab0a1/32.png) [@eugeniocesar](https://discuss.elastic.co/u/eugeniocesar)\
**Post date:** [May 23, 2016, 11:07pm UTC](https://discuss.elastic.co/t/help-with-aggregation-using-script-fields/50781/1 "2016-05-23T23:07:20Z")

</div>

Hi,

I would like to know how to retrieve a field value from the same \_source of another field, using the “scripted fields” feature of ES.

For example, I have the following \_source:  
`{ "_index": "logstash-2016.05.17", "_type": "openldap", "_id": "AVTBKXIvwxbdH8mztObX", "_score": null, "_source": { "message": "May 17 20:59:59 openldap-master slapd[14507]: conn=16206099 op=2 BIND dn='cn=user1,ou=users,dc=example,dc=com' method=128", "@version": "1", "@timestamp": "2016-05-17T23:59:59.000Z", "type": "openldap", "host": "openldap-server", "path": "/var/log/slapd.log", "timestamp": "May 17 20:59:59", "logsource": "openldap-master", "program": "slapd", "pid": "14507", "ConnNumber": "16206099", "OpType": "BIND", "BindDN": "cn=user1,ou=users,dc=example,dc=com" }, "fields": { "@timestamp": [1463529599000] }, "sort": [1463529599000] }`

I would like to query the value 16206099 in the field “ConnNumber” and retrieve the value of the field “BindDN” from the same \_source entry.

Any help would be very appreciated!

---

<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:** [July 5, 2017, 10:49pm UTC](https://discuss.elastic.co/t/help-with-aggregation-using-script-fields/50781/2 "2017-07-05T22:49:41Z")

</div>


