Script_score with multiline code

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"
	}
}

I have find an answer here: [Painless] Stored script - Multiline - Parsing Error

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

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