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
4
votes
2 answers
Easticsearch reindexing multi-type parent/child index(v5.0) to join type index(v6.2)
I am reindexing my index data from ES 5.0(parent-child) to ES 6.2(Join type)
Data in index ES 5.0 is stored as parent-child documents in separate types and for reindex i have created new index/mapping based on 6.2 in my new cluster.
The parent…

shivg
- 742
- 1
- 8
- 28
4
votes
2 answers
Elasticsearch painless, how to determine the data type of a field
In es5.5, how to determine whether a field is numeric?
if (is_numeric(ctx._source.some)) {
ctx._source.some = ctx._source.some + 2
}

Allen_Tsang
- 555
- 1
- 6
- 14
4
votes
0 answers
How to compare dates in elasticsearch painless script?
I honestly don't know who named it painless, because it really isn't, and the documentation isn't accurate for sure.
First of all, the field I'm trying to compare to a date is mapped as date.
The script itself looks something like this:
Date max =…

Andrew
- 2,063
- 3
- 24
- 40
4
votes
3 answers
How to validate Elasticsearch Painless scripts?
We use many ScriptQuery and ScriptField in our project, and provide inline scripts for them in painless language.
My question is, how can we validate these painless scripts? In other words, how to make sure that they will compile?
The approach we…

Sunil Purushothaman
- 8,435
- 1
- 22
- 20
4
votes
2 answers
Scripted field to count array length
I have the following document:
{
"likes": {
"data": [
{
"name": "a"
},
{
"name": "b"
},
{
"name": "c"
}
]
}
}
I'm trying to run an update_by_query that will add a field called…

Or Weinberger
- 7,332
- 23
- 71
- 116
3
votes
1 answer
Loop though ElasticSearch documents source array in painless
I have the following ElasticSearch data structure for products in a webshop:
{
"_index": "vue_storefront_catalog_1_product_1617378559",
"_type": "_doc",
"_source": {
"configurable_children": [
{
"price": 49.99,
…

Therm Scissorpunch
- 43
- 1
- 5
3
votes
2 answers
Split a string in Painless/ELK
I have a string field "myfield.keyword", where entries have the following format:
AAA_BBBB_CC
DDD_EEE_F
I am trying to create a scripted field that outputs the substring before the first _, a scripted field that outputs the substring between the…

gbs
- 45
- 1
- 1
- 7
3
votes
1 answer
how to access scripted field value in another script field
I'm trying to create a Scripted Field like :
return doc[scripted_field_a].value+doc[scripted_field_b].value
how to access to scripted field value in painless script ?
Thank you for any help!

Alex
- 93
- 6
3
votes
1 answer
How can i use Java's ArrayList class in painless script of Elasticsearch?
I want to write a script for script_score in elasticsearch.
In Painless Documentation there is a list of java classes under "Shared api reference".
GET hockey/_search
{
"explain": true,
"query": {
"match_all": {}
},
"script_fields": {
…

Abhinav Keshri
- 595
- 5
- 20
3
votes
1 answer
ElasticSearch - Access array of date_range in painless script filter
Is there any way to access an array of date_range in a painless script filter?
My mapping for the "blocked_dates" field is as follows:
"blocked_dates": {
"type": "date_range",
"format": "strict_date"
},
Data looks like…

ArcadeRenegade
- 804
- 9
- 14
3
votes
0 answers
How To replace depricated Joda dateformats using toString() with Java DateTimeFormatter in Elastic Painless Scripts?
Elastic Search Painless scripts returns a warning that a date format using
date.toString('HH') will be Deprecated.
Following warning:
! Deprecation: 299 Elasticsearch-6.7.0-8453f77 "Use of the joda time method [toString(String)] is deprecated. Use…

Dawid Parvulescu
- 31
- 6
3
votes
3 answers
How to generate a UUID in Elasticsearch reindex painless script
I am trying to use the reindex api to create a copy of a set of documents. One of the fields (uuid) of the document is a UUID. I need the copied documents to have new UUIDs for the uuid field.
According to [1] and [2] the method…

Oliver Henlich
- 283
- 4
- 13
3
votes
1 answer
Is there a way to compare string alphabetically in painless
I would like to execute this kind of operation in painless :
if (_value >= 'c)' {
return _value
} else {
return '__BAD__'
}
value is a string and I would like this following behaviour :
if value is foo I want to replace it with __BAD__ if the…

Julien TASSIN
- 5,004
- 1
- 25
- 40
3
votes
0 answers
Recursively initialize field with empty object in deep Elasticsearch documents
I currently have a deep nested object in one of my mappings:
{
"doc": {
"properties": {
"biography": {
"properties": {
"en": {
"properties": {
"event": {
"type": "nested",
…

villasv
- 6,304
- 2
- 44
- 78
3
votes
1 answer
Elasticsearch painless script not replacing the nested object field value using if condition
I just started with ES and still leaning the tricks of the trade!!!
I need to replace/overwrite one of the fields of a nested object type.
Here is the sample doc:
{
"name":"db_ref",
"ref_counter":[
{"ref_name":"test1","count":1},
…

ramd
- 347
- 2
- 12