# How to add scripted field to my custom endpoint?

**URL:** <https://discuss.elastic.co/t/how-to-add-scripted-field-to-my-custom-endpoint/186215>\
**Category:** Kibana\
**Created:** [June 18, 2019, 9:39am UTC](https://discuss.elastic.co/t/how-to-add-scripted-field-to-my-custom-endpoint/186215 "2019-06-18T09:39:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![masterThomas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/masterthomas/32/42765_2.png) [@masterThomas](https://discuss.elastic.co/u/masterThomas)\
**Post date:** [June 18, 2019, 9:39am UTC](https://discuss.elastic.co/t/how-to-add-scripted-field-to-my-custom-endpoint/186215/1 "2019-06-18T09:39:03Z")

</div>

hi team, my code is like :

```
server.route({
	path: '/api/combineindexes',
	method: 'GET',
	handler(req, h) {
		const qqq = {
			index: "*index1,*index2",
			q: "rule_id:*",
			script_fields: {
				"my_field" : {
					"script" : {
						"lang": "painless",
						"source": "doc['rule_id'].value"
					}
				}
			}
		}
		callWithRequest(req, 'search', qqq)
		return h.response(callWithRequest);
	}
});

```

but i receive error like

```
Unhandled rejection [illegal_argument_exception] request [/*alerts,*correlationsearches-lookup/_search] contains unrecognized parameter: [script_fields] -> did you mean any of [stored_fields, suggest_field, docvalue_fields]?

```

my task is to combine and transform fields from two indexes

---

<div class="post-metadata">

**Author:** ![joelgriffith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joelgriffith/32/53738_2.png) [@joelgriffith](https://discuss.elastic.co/u/joelgriffith)\
**Post date:** [July 11, 2019, 5:48pm UTC](https://discuss.elastic.co/t/how-to-add-scripted-field-to-my-custom-endpoint/186215/2 "2019-07-11T17:48:38Z")

</div>

What version of ElasticSearch/Kibana are you using?

---

<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:** [August 8, 2019, 5:48pm UTC](https://discuss.elastic.co/t/how-to-add-scripted-field-to-my-custom-endpoint/186215/3 "2019-08-08T17:48:41Z")

</div>

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