Elasticsearch Script
Elasticsearch Script
27-000001/_update/
190982
{
"script": {
"source": """
if (ctx._source.containsKey('metrics') &&
ctx._source.metrics.containsKey('playerMetrics')) {
for (int i = 0; i < ctx._source.metrics.playerMetrics.size(); i++) {
def playerMetrics = ctx._source.metrics.playerMetrics[i].playerMetrics;
if (playerMetrics != null) {
playerMetrics['cashoutMultiplier'] = params.cashoutMultiplier;
playerMetrics['conversionRate'] = params.conversionRate;
}
}
}
ctx._source.totalStake = params.totalStake;
ctx._source.totalReturn = params.totalReturn;
""",
"params": {
"totalStake": 984,
"totalReturn": 1,
"cashoutMultiplier": 1,
"conversionRate": 2
}
}
}
POST /.ds-topspin-testing-demo-multiplayer-gameround-2023.10.27-000001/_update/
190982
{
"script": {
"source": """
if (ctx._source.containsKey('metrics') &&
ctx._source.metrics.containsKey('playerMetrics')) {
for (int i = 0; i < ctx._source.metrics.playerMetrics.size(); i++) {
def playerMetrics = ctx._source.metrics.playerMetrics[i].playerMetrics;
if (playerMetrics != null) {
// Fetch the exchange rates from the currency API
def currencyApiUrl = 'https://currency-api.topspingames.net/latest?
baseCurrency=INR'
def currencyApiResponse = ctx.httpClient.get(currencyApiUrl);
***********************************************************************************
POST /.ds-prod-parimatch-multiplayer-gameround-2023.11.01-000001/_update_by_query
{
"script": {
"source": """
boolean isINR = false; // Initialize a variable to false
def initialConversionRate = null;
if (ctx._source.containsKey('metrics') &&
ctx._source.metrics.containsKey('playerMetrics')) {
for (int i = 0; i < ctx._source.metrics.playerMetrics.size(); i++) {
def playerMetrics = ctx._source.metrics.playerMetrics[i].playerMetrics;
if (playerMetrics != null && playerMetrics['currency'] == 'KZT') {
isINR = true; // Set the variable to true if currency is INR
if (playerMetrics.containsKey('conversionRate')) {
initialConversionRate = playerMetrics['conversionRate'];
playerMetrics['conversionRate'] = (playerMetrics['conversionRate'] /
initialConversionRate)*0.17782; // Divide by 82.45
}
}
}
}
if (isINR && ctx._source.containsKey('totalStake') &&
ctx._source.containsKey('totalReturn')) {
if (initialConversionRate != null) {
ctx._source.totalStake = ctx._source.totalStake / initialConversionRate;
ctx._source.totalReturn = ctx._source.totalReturn /
initialConversionRate;
}
}
""",
"params": {}
},
"query": {
"terms": {
"_id": ["55636856"]
}
}
}
***********************************************************************************
******
POST /.ds-stage-gametech-multiplayer-gameround-2023.10.23-000001/_update_by_query
{
"script": {
"source": """
def totalStake = 0.0;
def totalReturn = 0.0;
if (ctx._source.containsKey('metrics') &&
ctx._source.metrics.containsKey('playerMetrics')) {
for (def playerMetric : ctx._source.metrics.playerMetrics) {
if (playerMetric != null &&
playerMetric.playerMetrics.containsKey('isPlayForFun') &&
playerMetric.playerMetrics['isPlayForFun'] == false) {
if (playerMetric.playerMetrics.containsKey('conversionRate') &&
playerMetric.playerMetrics.containsKey('betAmount')) {
// Log totalStake before updating
ctx._source['log_totalStake_before'] = totalStake;
totalStake += playerMetric.playerMetrics['conversionRate'] *
playerMetric.playerMetrics['betAmount'];
ctx._source.totalStake = totalStake;
ctx._source.totalReturn = totalReturn;
""",
"params": {}
},
"query": {
"terms": {
"_id": ["8197863"]
}
}
}
***********************************************************************************
****************************
if (ctx._source.containsKey('metrics') &&
ctx._source.metrics.containsKey('playerMetrics')) {
for (def playerMetric : ctx._source.metrics.playerMetrics) {
if (playerMetric != null &&
playerMetric.playerMetrics.containsKey('isPlayForFun') &&
playerMetric.playerMetrics['isPlayForFun'] == false) {
if (playerMetric.playerMetrics.containsKey('conversionRate') &&
playerMetric.playerMetrics.containsKey('betAmount')) {
// Log totalStake before updating
// ctx._source['log_totalStake_before'] = totalStake;
totalStake += playerMetric.playerMetrics['conversionRate'] *
playerMetric.playerMetrics['betAmount'];
ctx._source.totalStake = totalStake;
ctx._source.totalReturn = totalReturn;
""",
"params": {}
},
"query": {
"terms": {
"_id":
["2263977","2263981","2263988","2263991","2263997","2264004","2264007","2264011","2
264017"]
}
}
}
POST /.ds-prod-gametech-multiplayer-gameround-2023.10.26-000001/_update_by_query
{
"script": {
"source": """
// Create an object to store the summation for each player
def playerCommandSummation = [:];
// Iterate through playerMetrics array and update only one object for each
playerId
for (def metrics : ctx._source.metrics.playerMetrics) {
def playerId = metrics.playerId;
if (differenceAmount.containsKey(playerId) && !
updatedPlayerIds.containsKey(playerId)) {
// Update one object for each playerId with the differenceAmount
metrics.playerMetrics.winAmount = (metrics.playerMetrics.winAmount ?:
0.0) + differenceAmount[playerId];
updatedPlayerIds[playerId] = true; // Mark playerId as updated
}
}
""",
"params": {}
},
"query": {
"terms": {
"_id": ["8694590"]
}
}
}