I have setup a page that calculates the total number of points that a user
has on a server. I am not trying to convert that to a level number. Here is
what I have but it is not working. Any help of ideas would be great. I just
cant seem to wrap my head around this. Thanks.
PlayerScore.score is calculated before on the page and works correctly.
This will not seem to work at all.
"script_fields": {
"PlayerScore.level": {
"script": "if (doc['PlayerScore.score'].value <= 100) {
(doc['PlayerScore.level'].value == 1) }else (doc['PlayerScore.score'].value
<= 300) { (doc['PlayerScore.level'].value == 2) }
else (doc['PlayerScore.score'].value <= 500) {
(doc['PlayerScore.level'].value == 3) }
else (doc['PlayerScore.score'].value <= 900) {
(doc['PlayerScore.level'].value == 4) }
else (doc['PlayerScore.score'].value <= 1400) {
(doc['PlayerScore.level'].value == 5) }
else (doc['PlayerScore.score'].value <= 2000) {
(doc['PlayerScore.level'].value == 6) }
else (doc['PlayerScore.score'].value <= 2700) {
(doc['PlayerScore.level'].value == 7) }
else (doc['PlayerScore.score'].value <= 3500) {
(doc['PlayerScore.level'].value == 8) }
else (doc['PlayerScore.score'].value <= 5000) {
(doc['PlayerScore.level'].value == 9) }
else (doc['PlayerScore.score'].value >= 7500) {
(doc['PlayerScore.level'].value == 10) }"
}
},
Here is where I am adding it.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Leaderboard_model extends CI_Model {
function __construct() {
parent::__construct();
}
function get($serverId = NULL) {
$a3servers = $this->config->item("a3w_servers");
if (!isset($a3servers)) {
return new stdClass();
}
$serverConfig = NULL;
if (!is_string($serverId)) {
$serverConfig = reset($a3servers);
}
else if(array_key_exists($serverId,$a3servers)){
$serverConfig = $a3servers[$serverId];
}
if (!isset($serverConfig)) {
return new stdClass();
}
$query = <<<EOF
{
"from": 0,
"size": 1000,
"fields": [
"PlayerInfo.Name",
"PlayerScore.playerKills",
"PlayerScore.aiKills",
"PlayerScore.deathCount",
"PlayerScore.reviveCount",
"PlayerScore.captureCount",
"updatedAt_"
],
"script_fields": {
"PlayerScore.kdr": {
"script": "if (doc['PlayerScore.deathCount'].value == 0) {
doc['PlayerScore.playerKills'].value } else { Math.round(100 *
(doc['PlayerScore.playerKills'].value /
doc['PlayerScore.deathCount'].value))/100}"
}
},
"script_fields": {
"PlayerScore.score": {
"script": "if (doc['PlayerScore.deathCount'].value == 0) {
doc['PlayerScore.playerKills'].value } else { Math.round(2 *
doc['PlayerScore.playerKills'].value + doc['PlayerScore.aiKills'].value +
(5 * doc['PlayerScore.captureCount'].value))}"
}
},
"sort": {
"PlayerScore.playerKills": {
"order": "desc"
}
},
"filter": {
"and": [
{
"exists": {
"field": "PlayerScore.playerKills"
}
},
{
"exists": {
"field": "PlayerScore.playerKills"
}
},
{
"range": {
"updatedAt_": {
"gt": "now-1M"
}
}
}
]
}
}
EOF;
$page = trim($serverConfig["ES_Players_Index"], "/") . "/_search";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $page);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:
application/json'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
$json= curl_exec($ch);
curl_close ($ch);
if (!is_string($json)) {
return new stdClass();
}
$data = json_decode($json);
if (!is_object($data)) {
return new stdClass();
}
return $data;
}
}
--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/1e764a21-bfb1-429c-9bde-874e8135bbf9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.