How to avoid repeating the same sub-queries in a single POST request?


#1

Hi I have a set of sub-queries that I first need to find the MAX score of sub-queries (using dis_max) then add together the SUM of the sub-queries scores as the final score. Is there a way to put them together in one POST API call without repeating the exact same set of sub-queries in two places? Thank you.

e.g.:

{
	"query":{
		"bool":{
			"should":[{
				"dis_max":{
					"queries": [{...sub-queries...}]
				}
			},{
				"bool":{
					"should":[{...sub-queries...}]
				}
			}]
		}
	}
}

#2

Bump. Hoping someone in the know could shed some light.
And I have looked at query template, but the sub-queries here are not some fixed queries that one just fill in the parameters. The sub-queries are from user input so query template is not going to help.


#3

Bump. Hoping someone in the know could shed some light.


#4

Bump. Hoping someone in the know could shed some light.


#5

Do you all have to have a paid membership before the devs will answer your posts?


(Christian Dahlqvist) #6

As far as I know there is no way to avoid this duplication, and the lack of response may indicate that there isn't anyone else that has a solution either. Usually queries are assembled programatically, so I do not understand why this duplication would be a problem. Could you please elaborate?


#7

Thank you @Christian_Dahlqvist. I surely can take a No as the answer, I asked merely thinking I might have written my query poorly, as it just seemed unnecessarily pumping up the size of the POST request and I was hoping something like a function_score query that operates on _scores instead of _score, so that I can do Math.max(_scores) + Math.sum(_scores).


(system) #8

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