mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
parent
e11b96ca9c
commit
2cae575f53
20 changed files with 614 additions and 527 deletions
|
@ -86,7 +86,7 @@ GET /hockey-stats/_search
|
|||
"script_score": {
|
||||
"script": {
|
||||
"lang": "painless",
|
||||
"inline": "int total = 0; for (int i = 0; i < input.doc.goals.size(); ++i) { total += input.doc.goals[i]; } return total;"
|
||||
"inline": "int total = 0; for (int i = 0; i < input.doc['goals'].size(); ++i) { total += input.doc['goals'][i]; } return total;"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ GET /hockey-stats/_search
|
|||
"total_goals": {
|
||||
"script": {
|
||||
"lang": "painless",
|
||||
"inline": "int total = 0; for (int i = 0; i < input.doc.goals.size(); ++i) { total += input.doc.goals[i]; } return total;"
|
||||
"inline": "int total = 0; for (int i = 0; i < input.doc['goals'].size(); ++i) { total += input.doc['goals'][i]; } return total;"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ GET /hockey-stats/_search
|
|||
|
||||
You must always specify the index of the field value you want, even if there's only a single item in the field.
|
||||
All fields in Elasticsearch are multi-valued and Painless does not provide a `.value` shortcut. The following example uses a Painless script to sort the players by their combined first and last names. The names are accessed using
|
||||
`input.doc.first.0` and `input.doc.last.0`.
|
||||
`input.doc['first'].0` and `input.doc['last'].0`.
|
||||
|
||||
[source,sh]
|
||||
----------------------------------------------------------------
|
||||
|
@ -133,7 +133,7 @@ GET /hockey-stats/_search
|
|||
"order": "asc",
|
||||
"script": {
|
||||
"lang": "painless",
|
||||
"inline": "input.doc.first.0 + \" \" + input.doc.last.0"
|
||||
"inline": "input.doc['first'].0 + ' ' + input.doc['last'].0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -219,13 +219,13 @@ GET /hockey-stats/_search
|
|||
"full_name_dynamic": {
|
||||
"script": {
|
||||
"lang": "painless",
|
||||
"inline": "def first = input.doc.first.0; def last = input.doc.last.0; return first + \" \" + last;"
|
||||
"inline": "def first = input.doc['first'].0; def last = input.doc['last'].0; return first + ' ' + last;"
|
||||
}
|
||||
},
|
||||
"full_name_static": {
|
||||
"script": {
|
||||
"lang": "painless",
|
||||
"inline": "String first = (String)((List)((Map)input.get(\"doc\")).get(\"first\")).get(0); String last = (String)((List)((Map)input.get(\"doc\")).get(\"last\")).get(0); return first + \" \" + last;"
|
||||
"inline": "String first = (String)((List)((Map)input.get('doc')).get('first')).get(0); String last = (String)((List)((Map)input.get('doc')).get('last')).get(0); return first + ' ' + last;"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -727,4 +727,4 @@ Def
|
|||
static Long defToLong(def)
|
||||
static Float defToFloat(def)
|
||||
static Double defToDouble(def)
|
||||
-----
|
||||
-----
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue