# How to make a scripted field with list of keynames from index

**URL:** <https://discuss.elastic.co/t/how-to-make-a-scripted-field-with-list-of-keynames-from-index/219090>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [February 12, 2020, 10:41pm UTC](https://discuss.elastic.co/t/how-to-make-a-scripted-field-with-list-of-keynames-from-index/219090 "2020-02-12T22:41:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Goishin](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Goishin](https://discuss.elastic.co/u/Goishin)\
**Post date:** [February 12, 2020, 10:41pm UTC](https://discuss.elastic.co/t/how-to-make-a-scripted-field-with-list-of-keynames-from-index/219090/1 "2020-02-12T22:41:21Z")

</div>

I'm using Kibana to report on my test pass results. And I created a doc type that represents the testng-results.xml I get after a test pass finishes. My doctype description looks like this:

```
                "results": {
                "passed": {
                    "type": "integer"
                },
                "failed": {
                    "type": "integer",
                },
                "skipped": {
                    "type": "integer"
                },
                "start_time": {
                    "type": "date"
                },
                "duration_ms": {
                    "type": "long"
                },
                "test_classes": {
                    "name": {
                        "type": "string"
                    },
                    "test_methods": {
                        "name": {
                            "type": "string"
                        },
                        "status": {
                            "type": "string"
                        },
                        "signature": {
                            "type": "string"
                        },
                        "duration_ms": {
                            "type": "long"
                        },
                        "started_at": {
                            "type": "date"
                        }
                    }
                }
            }

```

(note: there's a bit of metadata at the top of this doctype that's a bit too identifying for the internet, so I left that part out)

The problem is that I'd like to get a list of all the tests that were run on a particular test pass. However, instead of giving me a list of those, the test name ends up as part of the index instead.  
So, when looking at the index, you see a lot of things like this:  
results.test\_classes.com.blah.foo.doo.duu.TestClassName1.keyword  
results.test\_classes.com.blah.foo.doo.duu.TestClassName2.keyword  
results.test\_classes.com.blah.foo.doo.duu.TestClassName3.keyword  
where the "com.blah.foo.doo.duu" is the package name of my test code.

I was expecting to be able to create a data table with all of the tests that were executed in that test pass, but I can't figure out a query to make this happen. Then I sat down to learn painless, because I thought I could just create a scripted field that iterated through all the test classes and added them all to the field. But for some reason, I'm having a really difficult time even doing that. Can someone guide me towards a viable solution for this?

---

<div class="post-metadata">

**Author:** ![Goishin](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Goishin](https://discuss.elastic.co/u/Goishin)\
**Post date:** [February 13, 2020, 12:10am UTC](https://discuss.elastic.co/t/how-to-make-a-scripted-field-with-list-of-keynames-from-index/219090/2 "2020-02-13T00:10:29Z")

</div>

Now I'm getting somewhere!!!!

What I needed to use was the right form of data in the right context. I've been trying all of this using the doc form like so:  
doc['my.field.name']  
however, I could never get that into a hashmap form where I could call ".keySet()" on it. Then I found the other form you can use to access data:  
params['\_source']['my']['field']['name'].keySet()  
And then, viola', it works!!!!

---

<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:** [March 12, 2020, 12:10am UTC](https://discuss.elastic.co/t/how-to-make-a-scripted-field-with-list-of-keynames-from-index/219090/3 "2020-03-12T00:10:30Z")

</div>

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