# Passing complex parameters to JSON Input

**URL:** <https://discuss.elastic.co/t/passing-complex-parameters-to-json-input/153007>\
**Category:** Kibana\
**Created:** [October 18, 2018, 1:31pm UTC](https://discuss.elastic.co/t/passing-complex-parameters-to-json-input/153007 "2018-10-18T13:31:08Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin854](https://avatars.discourse-cdn.com/v4/letter/k/b3f665/32.png) [@Kevin854](https://discuss.elastic.co/u/Kevin854)\
**Post date:** [October 18, 2018, 1:31pm UTC](https://discuss.elastic.co/t/passing-complex-parameters-to-json-input/153007/1 "2018-10-18T13:31:08Z")

</div>

I'm using JSON input for a kibana visualization and I've read that passing parameters can improve performance. Can I pass something more than just a simple string or number? I'd like to pass the current date in milliseconds so I can get the week to date sales:

```auto
{
  "script": {
    "inline": "Calendar today = Calendar.getInstance(); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); if (doc['i.Transaction Date'].date.getMillis() <= today.getTimeInMillis() && doc['i.Transaction Date'].date.getMillis()>=cal.getTimeInMillis()/86400000*86400000) { return doc['i.Sales'].value; } return 0;",
    "lang": "painless",
    "params" : {
      "currentDateInMillis" : Calendar.getInstance().getTimeInMillis()
    }
  }
}

```

However, this doesn't parse for me. (Note, I'm not using the param in the JSON Input here, just testing to see if it parses).

Any ideas?

---

<div class="post-metadata">

**Author:** ![spalger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spalger/32/14092_2.png) [@spalger](https://discuss.elastic.co/u/spalger)\
**Post date:** [October 22, 2018, 6:06pm UTC](https://discuss.elastic.co/t/passing-complex-parameters-to-json-input/153007/2 "2018-10-22T18:06:58Z")

</div>

The JSON input is sent to Elasticsearch as is, so the `Calendar.getInstance().getTimeInMillis()` part isn't going to parse as it is not valid JSON. We could add a feature to Kibana that allows requesting specific parameters, but I doubt it will be very broadly useful and might be tricky to implement correctly.

Can you describe in a bit more detail what you are using this script to do? I suspect there is a way to do it without scripting, but perhaps not.

---

<div class="post-metadata">

**Author:** ![Kevin854](https://avatars.discourse-cdn.com/v4/letter/k/b3f665/32.png) [@Kevin854](https://discuss.elastic.co/u/Kevin854)\
**Post date:** [October 22, 2018, 6:38pm UTC](https://discuss.elastic.co/t/passing-complex-parameters-to-json-input/153007/3 "2018-10-22T18:38:39Z")

</div>

I'm trying to get to-date metrics, like Year to date, month to date, etc, in Kibana. I'd like to display these in a table.

---

<div class="post-metadata">

**Author:** ![spalger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spalger/32/14092_2.png) [@spalger](https://discuss.elastic.co/u/spalger)\
**Post date:** [October 23, 2018, 3:01am UTC](https://discuss.elastic.co/t/passing-complex-parameters-to-json-input/153007/4 "2018-10-23T03:01:53Z")

</div>

Interesting, how are you doing that today? Can you share a screenshot of your visualization that shows the config?

---

<div class="post-metadata">

**Author:** ![Kevin854](https://avatars.discourse-cdn.com/v4/letter/k/b3f665/32.png) [@Kevin854](https://discuss.elastic.co/u/Kevin854)\
**Post date:** [October 23, 2018, 2:09pm UTC](https://discuss.elastic.co/t/passing-complex-parameters-to-json-input/153007/5 "2018-10-23T14:09:20Z")

</div>

Sure. I could also split rows with a Date Range bucket, but that would list my to-dates vertically, rather than across which is preferable.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/7/07af74246edd5e308c95fd695e089277c6387112.png)

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 24, 2018, 3:34am UTC](https://discuss.elastic.co/t/passing-complex-parameters-to-json-input/153007/6 "2018-10-24T03:34:29Z")

</div>

Are you able to share the aggregation part of the setting as well? I'm just trying to replicate something similar based on seeing this, and I'm missing part of your approach 🙂

---

<div class="post-metadata">

**Author:** ![Kevin854](https://avatars.discourse-cdn.com/v4/letter/k/b3f665/32.png) [@Kevin854](https://discuss.elastic.co/u/Kevin854)\
**Post date:** [October 24, 2018, 9:41am UTC](https://discuss.elastic.co/t/passing-complex-parameters-to-json-input/153007/7 "2018-10-24T09:41:49Z")

</div>

I'm using a sum aggregation on my i.Sales field. Is that what you're looking for?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 24, 2018, 9:44am UTC](https://discuss.elastic.co/t/passing-complex-parameters-to-json-input/153007/8 "2018-10-24T09:44:42Z")

</div>

That's the main metric agg right, what about the bucket?

I'm using a filter, and then trying to split rows using a weekly date histogram using a variant on your script

---

<div class="post-metadata">

**Author:** ![Kevin854](https://avatars.discourse-cdn.com/v4/letter/k/b3f665/32.png) [@Kevin854](https://discuss.elastic.co/u/Kevin854)\
**Post date:** [October 24, 2018, 12:54pm UTC](https://discuss.elastic.co/t/passing-complex-parameters-to-json-input/153007/9 "2018-10-24T12:54:30Z")

</div>

I'm using a Terms bucket with a keyword field like Sales Rep.

---

<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:** [November 21, 2018, 12:54pm UTC](https://discuss.elastic.co/t/passing-complex-parameters-to-json-input/153007/10 "2018-11-21T12:54:34Z")

</div>

Closed on November 21, 2018, 12:54pm UTC

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