# Script\_score with multiline code

**URL:** <https://discuss.elastic.co/t/script-score-with-multiline-code/241468>\
**Category:** Elasticsearch\
**Created:** [July 16, 2020, 1:24pm UTC](https://discuss.elastic.co/t/script-score-with-multiline-code/241468 "2020-07-16T13:24:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ClubberLang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/clubberlang/32/72169_2.png) [@ClubberLang](https://discuss.elastic.co/u/ClubberLang)\
**Post date:** [July 16, 2020, 1:24pm UTC](https://discuss.elastic.co/t/script-score-with-multiline-code/241468/1 "2020-07-16T13:24:01Z")

</div>

Hi,

I have a query, this one compute a score with painless. I try to use multiline painless, using """, but the parser seems to unlike this.

From what I understand, it should work, right ?

Here is my query for review.

```
"query": {
	"function_score": {
		"query": {
			"bool": {
				"should": [
					{
						"distance_feature": {
							"field": "geoLocations",
							"pivot": "{{distance_pivot}}",
							"origin": [
								-71.3,
								41.15
							]
						}
					},
					{
						"distance_feature": {
							"field": "updateTime",
							"pivot": "{{time_pivot}}",
							"origin": "now"
						}
					},
					{
						"query_string": {
							"fields": [
								"tags^3",
								"taxonomies^5"
							],
							"query": "{{preferedKeywords}}",
							"fuzziness": "auto"
						}
					},

					{
						"nested": {
							"path": "imageTags",
							"score_mode": "sum",
							"query": {
								"function_score": {
									"query": {
										"query_string": {
											"fields": [
												"imageTags.tag^5"
											],
											"query": "{{preferedKeywords2}}",
											"fuzziness": "auto",
											"default_operator": "AND"
										}
									},
									"field_value_factor": {
										"field": "imageTags.score",
										"factor": 1,
										"missing": 0
									}
								}
							}
						}
					},
					{
						"nested": {
							"path": "imageTags",
							"score_mode": "sum",
							"query": {
								"function_score": {
									"query": {
										"query_string": {
											"fields": [
												"imageTags.tag^2"
											],
											"query": "{{preferedKeywords3}}",
											"fuzziness": "auto",
											"default_operator": "OR"
										}
									},
									"field_value_factor": {
										"field": "imageTags.score",
										"factor": 1,
										"missing": 0
									}
								}
							}
						}
					}

		
				]
			}
		},
		"functions": [
			{
				"script_score": {
					"script": {
						"lang":"painless",
						"source": """
						Random rnd = new Random();

						return rnd.nextFloat() * 0.2 +
						(Math.sqrt(doc['commentsCount'].value)+
						Math.log(2 + doc['likesCount'].value)+
						Math.log(2 + doc['viewsCount'].value)) / 3;
						"""
					}
				}
			}
		],
		"score_mode": "avg"
	}
}
```

---

<div class="post-metadata">

**Author:** ![ClubberLang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/clubberlang/32/72169_2.png) [@ClubberLang](https://discuss.elastic.co/u/ClubberLang)\
**Post date:** [July 16, 2020, 2:42pm UTC](https://discuss.elastic.co/t/script-score-with-multiline-code/241468/2 "2020-07-16T14:42:41Z")

</div>

I have find an answer here: [[Painless] Stored script - Multiline - Parsing Error](https://discuss.elastic.co/t/painless-stored-script-multiline-parsing-error/211091)

So, multiline is not supported at all in Elastic ? (Only Kibana Dev Tool) ?

---

<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 13, 2020, 2:42pm UTC](https://discuss.elastic.co/t/script-score-with-multiline-code/241468/3 "2020-08-13T14:42:46Z")

</div>

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