# How to use parameters in a stored script that's executed using logstash output plugin

**URL:** <https://discuss.elastic.co/t/how-to-use-parameters-in-a-stored-script-thats-executed-using-logstash-output-plugin/298336>\
**Category:** Logstash\
**Tags:** painless\
**Created:** [February 26, 2022, 7:11pm UTC](https://discuss.elastic.co/t/how-to-use-parameters-in-a-stored-script-thats-executed-using-logstash-output-plugin/298336 "2022-02-26T19:11:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rui\_Goncalves](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rui_goncalves/32/72197_2.png) [@Rui\_Goncalves](https://discuss.elastic.co/u/Rui_Goncalves)\
**Post date:** [February 26, 2022, 7:11pm UTC](https://discuss.elastic.co/t/how-to-use-parameters-in-a-stored-script-thats-executed-using-logstash-output-plugin/298336/1 "2022-02-26T19:11:21Z")

</div>

Hi, I've a stored script :

```auto
POST _scripts/1_jd_job_domain
{
  "script": {
	"lang": "painless",
	"params": {
	  "generic_domain": "generic domain"
          [...]
	},
	"source" : """if ( ctx._source.car?.current_assignment?.job_description?.jdl1_id_reports_to != null && ctx._source.car?.current_assignment?.job_description?.jdl3_id_reports_to != null)  
                     { Map map_generic_details = new HashMap()
		     ; ArrayList list_domain_list = new ArrayList()
		     ; map_generic_details.put('index type' , params.generic_domain)
	   	    ;map_generic_details.put('value',params.generic_plus_specific_plus_intermediate)
                    [...]

```

I call this script from logstash output plugin. It works fine for the rest except it doesn't retrieve the values from the params. What am I doing wrong ?

I've also tried defining those params in the logstsh output part like this :  
parameters =\> {"generic\_domain" =\> "generic\_domain"}

but then I've the error:  
Response code '400' contacting Elasticsearch at URL '[http://localhost:9200/?generic\_domain=generic\_domain](http://localhost:9200/?generic_domain=generic_domain)'"}

What am I doing wrong? I would prefer a solution where I could get the parameters values from the stored script if possible. Thank you

---

<div class="post-metadata">

**Author:** ![Rui\_Goncalves](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rui_goncalves/32/72197_2.png) [@Rui\_Goncalves](https://discuss.elastic.co/u/Rui_Goncalves)\
**Post date:** [February 28, 2022, 8:50am UTC](https://discuss.elastic.co/t/how-to-use-parameters-in-a-stored-script-thats-executed-using-logstash-output-plugin/298336/2 "2022-02-28T08:50:58Z")

</div>

On the logstash output I've tried :

```auto
parameters => { "event" => {"taxless_total_price" => "90"}}
But now it shows the error : Pipeline aborted due to error {:pipeline_id=>"main", :exception=>java.net.URISyntaxException: Illegal character in query at index 54: http://elastic:secret4hrsearch@localhost:9200/?event=["taxless_total_price", "90"]

```

could you help please, tanks.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [February 28, 2022, 2:34pm UTC](https://discuss.elastic.co/t/how-to-use-parameters-in-a-stored-script-thats-executed-using-logstash-output-plugin/298336/3 "2022-02-28T14:34:08Z")

</div>

I think the `parameters` option should just be `{ "key1" => "value1" "key2" => "value2" }`. Otherwise the [flat\_map](https://github.com/logstash-plugins/logstash-output-elasticsearch/blob/fe0a24135a6f18f64415a116f09bc5418b83f15e/lib/logstash/outputs/elasticsearch/http_client.rb#L381) call will create an array which needs to be encoded.

---

<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 28, 2022, 2:35pm UTC](https://discuss.elastic.co/t/how-to-use-parameters-in-a-stored-script-thats-executed-using-logstash-output-plugin/298336/4 "2022-03-28T14:35:00Z")

</div>

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