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
23
votes
2 answers
Elasticsearch painless script error
I have no Java experience and I have an issue with elasticsearch painless script language. (the name painless it's not well chosen).
For the following code I get the error:
{"lang": "painless",
"inline": "float price = doc['newPrice'] > 0.0 ?…

Alexandru R
- 8,560
- 16
- 64
- 98
10
votes
2 answers
How do I list all stored scripts on an Elasticsearch cluster?
I would like to be able to list all of the scripts stored on a given Elasticsearch cluster.
The elasticsearch documentation has clear examples for how to create, retrieve, use and delete a script with a particular name. Unfortunately, there is no…

billkw
- 3,350
- 3
- 28
- 32
10
votes
2 answers
How to create and add nested object into nested field in Elasticsearch?
https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html
Consider:
PUT my_index
{
"mappings": {
"_doc": {
"properties": {
"user": {
"type": "nested"
}
}
}
}
}
PUT…

tom10271
- 4,222
- 5
- 33
- 62
9
votes
2 answers
elasticsearch-painless - Manipulate date
I am trying to manipulate date in elasticsearch's scripting language painless.
Specifically, I am trying to add 4 hours, which is 14,400 seconds.
{
"script_fields": {
"new_date_field": {
"script": {
"inline": "doc['date_field'] +…

Eran H.
- 1,146
- 1
- 8
- 18
8
votes
2 answers
painless: check if an individual document contains a key
I'm using painless to filter documents with Elastic 5.5
Problem
Using "painless", find documents with strings field.
Expected Results
Only documents with strings field are returned
Actual Results
All documents are returned.
Observation
All documents…

Maryan
- 1,484
- 1
- 12
- 16
7
votes
1 answer
how to check for key exist in elastic-search painless parameters?
How to check for key exists in painless script map parameters.
In below query check a.toString() key exist in params
I've tried everything but didn't get it to work.
Please help me
mapping :
"id": {
"type": "long"
}
query:
{
"query":{
…

slifer2015
- 682
- 6
- 12
7
votes
2 answers
Elasticsearch Painless: Error when using three quotes: Unexpected Character ('\"' (code 34))
I'm running a local instance of Elasticsearch, and trying to work with 'painless' under scripted_fields. I can write a single line of script code just fine, but when I use triple-quotes (which is supported as per documentation) to create a…

Jeremy
- 141
- 1
- 5
7
votes
1 answer
Elasticsearch Painless calculate score from nested elements
Note: I had originally posted this question a little differently and it wasn't worth updating as after reading I learned a bit more.
Requirement
Search for documents and calculate a custom score based on nested elements within the…

el n00b
- 1,957
- 7
- 37
- 64
7
votes
1 answer
elasticsearch doc['...'] Arrays and order
i need to access document values stored in arrays from script. The order of the items in the array is important.
using doc['...'] to retrieve the array will mix up the order :-(
suppose a simple document like this
{
…

Holger Will
- 7,228
- 1
- 31
- 39
6
votes
2 answers
Elasticsearch - Script Filter over a list of nested objects
I am trying to figure out how to solve these two problems that I have with my ES 5.6 index.
"mappings": {
"my_test": {
"properties": {
"Employee": {
"type": "nested",
"properties": {
…

betto86
- 694
- 1
- 8
- 23
6
votes
1 answer
Why is an array adding to an array with painless script?
Using Logstash, my goal is to index the document if the timestamp for that document hasn't been indexed before, otherwise, if the document does exist and the timestamp is not in the array, then append the timestamp array. My problem is that an array…

helpzmepleasekthxbye
- 73
- 1
- 6
6
votes
1 answer
How to perform date arithmetic between nested and unnested dates in Elasticsearch?
Consider the following Elasticsearch (v5.4) object (an "award" doc type):
{
"name": "Gold 1000",
"date": "2017-06-01T16:43:00.000+00:00",
"recipient": {
"name": "James Conroy",
"date_of_birth": "1991-05-30"
}
}
The mapping type for…

JoeLinux
- 4,198
- 1
- 29
- 31
6
votes
2 answers
In Elasticsearch, how can I apply a timezone to a scripted date operation?
With the aggregation below and using ES5, I'd like to get the dayOfWeek & hourOfDay based on a given timezone (supplied as an identifier from the TZ database).
How can I edit "doc['created'].date.dayOfWeek' to adjust for the offset?
aggs: {
…

Oliver Lloyd
- 4,936
- 7
- 33
- 55
5
votes
0 answers
Painless new behaviour for nulls in version 7.x
After the upgrade from version 6 to 7, we are experiencing a new behavior when processing aggregation. Now, whenever the Elastic comes across with a null value in a field while running a Painless script it breaks, by default.
For example, the…

Paulo Henrique PH
- 324
- 1
- 4
- 15
5
votes
1 answer
ElasticSearch: Delete field from all documents where it exists (with Painless?)
Situation: I have an index with strict mapping and I want to delete an old field from it which is no longer used. So I create a new index with mapping that doesn't include that field and I try to reindex the data into the new index.
Problem: When I…

pmishev
- 896
- 9
- 22