Painless is a scripting language that is purpose-built for Elasticsearch. It was introduced with Elasticsearch 5.0. Painless can be used anywhere in Elasticsearch where scripts can normally be run by specifying the 'lang' parameter as 'painless'.
Questions tagged [elasticsearch-painless]
484 questions
2
votes
1 answer
ElasticSearch Script get value of current year
I'm trying to make a script within my rescore function to check if the bibliographic release date (doc['bibliografische_verschijningsdatum']), is the same as the commercial release date (doc['verschijningsdatum']).
AND the…

Elvira
- 1,410
- 5
- 23
- 50
2
votes
0 answers
NullPointerExceptions when accessing ElasticSearch painless scripted metric aggregation params
When accessing doc within map_script of a scripted aggregation, I keep getting a null pointer exception.
For
{
"init_script":{
"source":"params._agg['transactions'] = [];"
},
"map_script":{
…

Joe - GMapsBook.com
- 15,787
- 4
- 23
- 68
2
votes
2 answers
Painless: Get time difference
I am very new to Painless. I want to write a simple script to get the time difference between @timestamp and T1 in milliseconds.
I have tried using the doc['somefield'].value and doc['somefield'].date.millis and I am able to access @timestamp but…

Saurav Tripathy
- 31
- 1
- 4
2
votes
1 answer
ElasticSearch - difference between two date fields
I have an index in ElasticSearch with two fields of date type (metricsTime & arrivalTime). A sample document is quoted below. In Kibana, I created a scripted field delay for the difference between those two fields. My painless script…

Averell
- 793
- 2
- 10
- 21
2
votes
2 answers
Elasticsearch: comparing dates (painless script)
My mapping of createdAt:
"createdAt": {
"type": "date"
},
I insert the dates like this:
POST logs/_doc/_bulk?pretty
{"index":{"_id":1}}
{"createdAt":"2018-05-01T07:30:00Z","value":"on"}
When I request the documents
GET logs/_doc/_search
It…

scth
- 61
- 1
- 2
- 6
2
votes
0 answers
Merge parent and a child document in to one single doc
Is it possible to combine a parent document and a child document of the same parent in to a single doc with fields from both documents using either reindex or scripting?
For example, let's say parent document have fields A,B,C,D and child documents…

Nithin Chandy
- 686
- 1
- 10
- 28
2
votes
0 answers
How can I compile a regex in Elasticsearch 5x's Painless syntax
I have a need to compile a regex defined by a parameter in Painless.
My initial assumption would be that I could do something similar to the following:
Pattern p = Pattern.compile(params.myPattern);
However, I am getting the following…

brett
- 21
- 1
2
votes
1 answer
Looping through hits using painless script
Is there a way In Elasticsearch 5.3 to loop through query results using painless script to compute difference between the hits returned by query.
I was trying to loop through the results in a for loop in script and could not what entity to loop on,…

kiran6
- 1,247
- 2
- 13
- 19
2
votes
1 answer
Append element to Eslasticsearch field
please is possible to append some element to elasticsearch field if types doesn't match? If I have document like this:
{
"counter" : 1,
"tags" : "red"
}
and i want to append another tag field f.e "blue" like this:
{
"script" : {
"source":…

user1439198
- 37
- 2
- 8
2
votes
1 answer
Elasticsearch painless get string field (which contains XML) into a variable
I'm trying to parse an Elasticsearch string field (named Request.Body) which contains XML. This field contains a SOAP request string, like this :

Dorian
- 761
- 3
- 11
- 28
2
votes
1 answer
Date math in elastic watcher email
I would like to find the datetime for 1 day ago so that I can create link to kibana in an email sent from the watcher. Using Elasticsearch 5.0.2
I've tried the watch below but it returns an error of
ScriptException[runtime error]; nested:…

Scott Cowan
- 2,652
- 7
- 29
- 45
2
votes
0 answers
ElasticSearch Reindex API and painless script to access date field
I try to familiarize myself with the Reindexing API of ElasticSearch and the use of Painless scripts.
I have the following model:
"mappings": {
"customer": {
"properties": {
"firstName": {
"type": "text",
…

Peter Szekeli
- 2,712
- 3
- 30
- 44
2
votes
1 answer
Traversing a HashMap by its sorted keys
I try to figure out how I could iterate on a Painless HashMap values by its keys sorted in ascending order, the following doesn't work:
HashMap buckets;
for(String bucketKey : new TreeSet(buckets.keySet())) {
// actual code
}

nfroidure
- 1,531
- 12
- 20
2
votes
1 answer
Select document field with parameter in elasticsearch update by query API
ElasticSearch version = 5.5
I've inherited some code that updates arbitrary document fields via the update by query API to an arbitrary value like this:
{
"query": ...
"script": {
"inline": "ctx._source." + field + " = " + value + ";"
}
…

elhefe
- 3,404
- 3
- 31
- 45
2
votes
2 answers
How can I access script fields in queries made with NEST on Elasticsearch?
I have a POCO that has a coordinate field, and the mapping and geodistance search with NEST all works as expected. However, what I'm trying to do with NEST is to also return the distance from the point specified in the GeoDistance query as part of…

Henry C
- 4,781
- 4
- 43
- 83