A functional script query is working fine when i dont add certain scripts to it but it fails and returns > [script] Too many dynamic script compilations within, max: [75/5m]; please use indexed, or scripts with parameters instead; this limit can be changed by the [script.max_compilations_rate] setting > this error when i add mainly 2 scripts to it. Also this is not happening everytime, sometimes it works fine but most of the times it returns error. Below are the queries :
Working query :
{
"_source": false,
"query": {
"function_score": {
"functions": [
{
"script_score": {
"script": {
"source": "doc['profile_completed_score'].value >0 ? doc['profile_completed_score'].value * 0.15 : 0"
}
}
},
{
"script_score": {
"script": {
"source": "if(!doc['profile_pic'].empty)return 10; return 0;"
}
}
},
{
"gauss": {
"city_geolocation": {
"origin": {
"lat": "28.536000",
"lon": "77.391000"
},
"scale": "100km",
"offset": "100km",
"decay": 0.0001
}
},
"weight": 15
},
{
"script_score": {
"script": {
"source": "def designation=0; if(doc['designation_name.keyword'].value != null && doc['designation_name.keyword'].value==params.designation) { designation=30; } else { if(doc['designation_name.keyword'].value != null && (doc['designation_name.keyword'].value.toUpperCase().indexOf(params.designation.toUpperCase())>-1 || params.designation.toUpperCase().indexOf(doc['designation_name.keyword'].value.toUpperCase())>-1)) designation=15; } return designation;",
"params": {
"designation": "Technical Manager"
}
}
}
},
{
"script_score": {
"script": {
"source": "def visited=0;def vscore=0;if(!doc['visited_event'].empty && doc['visited_event'].values.contains(params.fact))visited=10;if(!doc['avg_visitor_score'].empty)vscore=doc['avg_visitor_score'].value*0.2; return visited+vscore;",
"params": {
"fact": "13039"
}
}
}
}
],
"score_mode": "sum",
"boost_mode": "replace"
}
},
"size": 20,
"from": 0
}
Query returning error most of times :
{
"_source": false,
"query": {
"function_score": {
"functions": [
{
"script_score": {
"script": {
"source": "doc['profile_completed_score'].value >0 ? doc['profile_completed_score'].value * 0.15 : 0"
}
}
},
{
"script_score": {
"script": {
"source": "if(!doc['profile_pic'].empty)return 10; return 0;"
}
}
},
{
"gauss": {
"city_geolocation": {
"origin": {
"lat": "28.536000",
"lon": "77.391000"
},
"scale": "100km",
"offset": "100km",
"decay": 0.0001
}
},
"weight": 15
},
{
"script_score": {
"script": {
"source": "def designation=0; if(doc['designation_name.keyword'].value != null && doc['designation_name.keyword'].value==params.designation) { designation=30; } else { if(doc['designation_name.keyword'].value != null && (doc['designation_name.keyword'].value.toUpperCase().indexOf(params.designation.toUpperCase())>-1 || params.designation.toUpperCase().indexOf(doc['designation_name.keyword'].value.toUpperCase())>-1)) designation=15; } return designation;",
"params": {
"designation": "Technical Manager"
}
}
}
},
{
"script_score": {
"script": {
"source": "if(!doc['email_active'].empty && doc['email_active'].toInstant().toEpochMilli()/(params.divi) >= (params.epochtime)) return 30; return 0;",
"params": {
"divi": 1000,
"epochtime": 1607863137
}
}
}
},
{
"script_score": {
"script": {
"source": "if((!doc['checkin_edition'].empty && doc['checkin_edition'].contains(params.fact))) return 30; return 0;",
"params": {
"fact": "1330689"
}
}
}
},
{
"script_score": {
"script": {
"source": "def visited=0;def vscore=0;if(!doc['visited_event'].empty && doc['visited_event'].values.contains(params.fact))visited=10;if(!doc['avg_visitor_score'].empty)vscore=doc['avg_visitor_score'].value*0.2; return visited+vscore;",
"params": {
"fact": "13039"
}
}
}
}
],
"score_mode": "sum",
"boost_mode": "replace"
}
},
"size": 20,
"from": 0
}
I tried indexing the scripts and using them with parameters but it didn't work.
Also tried increasing the limit to 150/5m but it is breaking at some point again
Any kind of help is much appriciated.
Thanks//