# Keys\_under\_root option in configuration

**URL:** <https://discuss.elastic.co/t/keys-under-root-option-in-configuration/79602>\
**Category:** Beats\
**Tags:** beats-development\
**Created:** [March 22, 2017, 2:56pm UTC](https://discuss.elastic.co/t/keys-under-root-option-in-configuration/79602 "2017-03-22T14:56:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![krhubert](https://avatars.discourse-cdn.com/v4/letter/k/c2a13f/32.png) [@krhubert](https://discuss.elastic.co/u/krhubert)\
**Post date:** [March 22, 2017, 2:56pm UTC](https://discuss.elastic.co/t/keys-under-root-option-in-configuration/79602/1 "2017-03-22T14:56:41Z")

</div>

Hi,

Just wonder how to put keys\_under\_root like filebeat do in my own beat? Is this supported or documented somewhere?

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [March 22, 2017, 11:01pm UTC](https://discuss.elastic.co/t/keys-under-root-option-in-configuration/79602/2 "2017-03-22T23:01:24Z")

</div>

Can you provide more details about what you want to accomplish.

---

<div class="post-metadata">

**Author:** ![krhubert](https://avatars.discourse-cdn.com/v4/letter/k/c2a13f/32.png) [@krhubert](https://discuss.elastic.co/u/krhubert)\
**Post date:** [March 23, 2017, 6:50am UTC](https://discuss.elastic.co/t/keys-under-root-option-in-configuration/79602/3 "2017-03-23T06:50:41Z")

</div>

Sure,

The filebeat has such option:

```auto
keys_under_root
By default, the decoded JSON is placed under a "json" key in the output document. If you enable this setting, the keys are copied top level in the output document. The default is false.

```

What do I want to do?

I'm writing simple go program that processes documents that have a lot of string/double values and it's flat. I'm using [elastic](http://github.com/olivere/elastic) library to get the search results and every document data is stored under `_source` field and I have to parse the document every time. It would be easier to just get value by typing `document.Field["key"].(string)`, and I was wonder from curiosity if how to accomplish putting keys under root in libbeat.

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [March 23, 2017, 12:07pm UTC](https://discuss.elastic.co/t/keys-under-root-option-in-configuration/79602/4 "2017-03-23T12:07:42Z")

</div>

So if you are writing a Beat you are creating the output event that will be published. When you create the event you can populate it with the contents of the `_source` field.

I think you will have to unmarshal the `_source` field into a `map[string]interface{}`. Then once you have the `_source` field as an object you and create your event and populate it with the contents of `_source`.

```auto
source := // unmarshal _source JSON to map
myEvent := common.MapStr{
    "@timestamp": common.Time(time.Now()),
    "type": "mytype",
}
for k, v := range source {
    myEvent[k] = v
}

```

---

<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:** [April 20, 2017, 12:07pm UTC](https://discuss.elastic.co/t/keys-under-root-option-in-configuration/79602/5 "2017-04-20T12:07:48Z")

</div>

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