Hashmaps in params

I'm trying to send a list of lookup-values as parameters to a function_score script.

I'm trying to supply the script with a map of ID's that it will use to lookup the current documentId and use whatever value exists in the map for some calculation.

This is somewhat what i'm trying to do, but of course it doesn't compile.

ES 5.3.2

{
  "query": {
	"function_score": {
		  "script_score": {
			"script" : {
					"params": {
						"mapValues": { 
						  "A": 1.5,  //Custom value for document with ID=A
						  "B": 1.6,  //Custom value for document with ID=B
						  "C": 1.7   //Custom value for document with ID=C
						}
					},
					"inline": "def mapValue = params.mapValues.get(doc.Id); /* Do something */ "
			}
		  }
		}
  }
}

I know I could just use two arras and a loop (one with ids and another with values), but that would require the array to be iterated for every document, which is not optimal for performance reasons.

Does painless support any type of complex objects as parameters?

Hm, painless should support maps/objects like that (I've done similar in the past). What compile error are you getting?

I'm glad you asked me to give you the compile error, because it turned out that it's actually working as expected. I have no idea what was wrong with my setup before.

Anyways, thank you for at least taking the time to answer, otherwise I would have dropped the idea completely :smile:

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