# Kibana scripted fields and nested types - no value returned

**URL:** <https://discuss.elastic.co/t/kibana-scripted-fields-and-nested-types-no-value-returned/88780>\
**Category:** Kibana\
**Created:** [June 9, 2017, 3:04am UTC](https://discuss.elastic.co/t/kibana-scripted-fields-and-nested-types-no-value-returned/88780 "2017-06-09T03:04:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkhan](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@mkhan](https://discuss.elastic.co/u/mkhan)\
**Post date:** [June 9, 2017, 3:04am UTC](https://discuss.elastic.co/t/kibana-scripted-fields-and-nested-types-no-value-returned/88780/1 "2017-06-09T03:04:44Z")

</div>

How can one return a nested field value using the Scripted Fields in Kibana?

In the following painless script, given that the 'activity' is a 'nested' type, 'typecode' is text type, and 'keyword' is a 'keyword' type --- the following script doesn't return anything:

def someval = doc['activity.typeCode.keyword'].value;  
if(someval != null) {  
return someval;  
}  
return "";

Any advice is much appreciated.

---

<div class="post-metadata">

**Author:** ![cjcenizal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjcenizal/32/11216_2.png) [@cjcenizal](https://discuss.elastic.co/u/cjcenizal)\
**Post date:** [June 9, 2017, 6:47pm UTC](https://discuss.elastic.co/t/kibana-scripted-fields-and-nested-types-no-value-returned/88780/2 "2017-06-09T18:47:54Z")

</div>

Hi Mohammed,

That's strange, that looks right. Are you getting any errors? Can you double check that this field is both searchable and aggregatable in the Management \> Index Field page?

![](https://us1.discourse-cdn.com/elastic/original/3X/4/4/4463b6cf1517fc97e79175e4b66b527da22f8d1f.png)

Can you also try just returning the value without any conditionals?

```auto
doc['activity.typeCode.keyword'].value

```

Also I noticed that in the code snippet you pasted, `typeCode` is camel-case, but you refer to it as `typecode` later, which is all lower-case. Are you sure you're using the correct casing?

Thanks,  
CJ

---

<div class="post-metadata">

**Author:** ![mkhan](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@mkhan](https://discuss.elastic.co/u/mkhan)\
**Post date:** [June 13, 2017, 1:27am UTC](https://discuss.elastic.co/t/kibana-scripted-fields-and-nested-types-no-value-returned/88780/3 "2017-06-13T01:27:39Z")

</div>

Hi CJ,

Yep, I can see that the field is both 'searchable' and 'aggregatable'...

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

> [@cjcenizal](#):
>
> Can you also try just returning the value without any conditionals?
> 
> doc['activity.typeCode.keyword'].value

I tried just returning the value, it just shows a hypen (-) on the 'Discover' screen...  
 ![](https://us1.discourse-cdn.com/elastic/original/3X/6/3/636f4fc58b43a9ef5bfcccf2c183d39573dd7876.png)

And when I try to 'Visualize', following request and response are presented...

**Elasticsearch request body**

```auto
    {
      "size": 0,
      "query": {
        "bool": {
          "must": [
            {
              "query_string": {
                "analyze_wildcard": true,
                "query": "*"
              }
            },
            {
              "range": {
                "report.lastUpdateDatetime": {
                  "gte": 1434158649569,
                  "lte": 1497317049569,
                  "format": "epoch_millis"
                }
              }
            }
          ],
          "must_not": []
        }
      },
      "_source": {
        "excludes": []
      },
      "aggs": {
        "3": {
          "terms": {
            "script": {
              "inline": "doc['activity.typeCode.keyword'].value;",
              "lang": "painless"
            },
            "size": 20,
            "order": {
              "_count": "desc"
            },
            "valueType": "string"
          }
        }
      }
    }

```

**Elasticsearch response body**

```auto
    {
      "took": 4,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
      },
      "hits": {
        "total": 1,
        "max_score": 0,
        "hits": []
      },
      "aggregations": {
        "3": {
          "doc_count_error_upper_bound": 0,
          "sum_other_doc_count": 0,
          "buckets": []
        }
      },
      "status": 200
    }

```

No errors btw, but no data returned either.

Can you advise, please?

Thanks

---

<div class="post-metadata">

**Author:** ![cjcenizal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjcenizal/32/11216_2.png) [@cjcenizal](https://discuss.elastic.co/u/cjcenizal)\
**Post date:** [June 15, 2017, 12:55am UTC](https://discuss.elastic.co/t/kibana-scripted-fields-and-nested-types-no-value-returned/88780/4 "2017-06-15T00:55:00Z")

</div>

This is very strange! It looks like the response is getting one hit. What is the actual value at `activity.typeCode.keyword` within the document?

---

<div class="post-metadata">

**Author:** ![mkhan](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@mkhan](https://discuss.elastic.co/u/mkhan)\
**Post date:** [June 15, 2017, 1:12am UTC](https://discuss.elastic.co/t/kibana-scripted-fields-and-nested-types-no-value-returned/88780/5 "2017-06-15T01:12:39Z")

</div>

The actual value is 'PRIMARY' within the document for that field.

---

<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 13, 2017, 1:12am UTC](https://discuss.elastic.co/t/kibana-scripted-fields-and-nested-types-no-value-returned/88780/6 "2017-07-13T01:12:57Z")

</div>

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