# Fields aggregation or field formatter?

**URL:** <https://discuss.elastic.co/t/fields-aggregation-or-field-formatter/87023>\
**Category:** Kibana\
**Created:** [May 24, 2017, 6:15pm UTC](https://discuss.elastic.co/t/fields-aggregation-or-field-formatter/87023 "2017-05-24T18:15:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![LeeDr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leedr/32/9289_2.png) [@LeeDr](https://discuss.elastic.co/u/LeeDr)\
**Post date:** [May 26, 2017, 5:20pm UTC](https://discuss.elastic.co/t/fields-aggregation-or-field-formatter/87023/2 "2017-05-26T17:20:16Z")

</div>

Hi Chris,

I think a scripted field might help. Here's an experiment I did.

1. I put this data using Kibana dev console. Each doc has a name but in a different field;

```auto
PUT /discuss/test/1
{
    "date" : "2017-05-26T00:01:00",
    "name" : "Lee"
}

PUT /discuss/test/2
{
    "date" : "2017-05-26T00:02:00",
    "firstName" : "Bob"
}

PUT /discuss/test/3
{
    "date" : "2017-05-26T00:02:30",
    "fullName" : "Bart Simpson"
}

```

1. It looks like this in Discover;  
 ![](https://us1.discourse-cdn.com/elastic/original/3X/f/5/f56d5ae9d43987cd4f275c7fda58f8456a9cbc05.png)

Obviously I can already search on any of those names (without using the field name) and find the doc as long as the other docs don't also contain the names or parts of names in other fields.

But if I want one field I can always search on I can create a scripted field like this which uses the first of the values it finds;

`doc['name.keyword'].value ?: doc['firstName.keyword'].value ?: doc['fullName.keyword'].value ?: ''`

 ![](https://us1.discourse-cdn.com/elastic/original/3X/3/c/3c4f59641db157f73faa4ed6e0c439c54ab0d434.png)

Or this also works (might need one final return for the case where all three are null);

```auto
if (doc['name.keyword'].value != null)
  return doc['name.keyword'].value;
if (doc['firstName.keyword'].value != null)
  return doc['firstName.keyword'].value;
if (doc['fullName.keyword'].value != null)
  return doc['fullName.keyword'].value;

```

Regards,  
Lee

---

_[View the full topic](https://discuss.elastic.co/t/fields-aggregation-or-field-formatter/87023)._
