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
0 answers
How to write Elasticsearch painless script to create new document in an index and at same time update another index's document?
I want to write a painless script which can insert new document in an index and update the fields of another document in another index. Consider a scenario where there are two index (office and employee). office index have a field totalCount and…

hsraps
- 31
- 4
2
votes
2 answers
How to get the text body field in a painless script in the filter context of elastic search query?
I have constructed a elastic search query with a filter and in the filter context and I am writing a painless script to filter some documents based on the body of the text field. However, when I want to access the text field, I get a list of terms…

Rouzbeh
- 21
- 1
- 3
2
votes
1 answer
Elastic Search, use scripted field for an aggregation result
I would like to know if it is possible to have a scripted_field in the result of an aggregation:
An example query:
GET /index/_search
{
"query": {
"match_all": {}
},
"agg": {
"test": {
"terms": {
"field": "key"
}
…

Konrad
- 107
- 8
2
votes
1 answer
Why Painless compiler complains about `new` keyword?
I am trying to create string from bytes in Painless script, as below, but ending up with error around new keyword. Our Elasticsearch is 6.2.8.
(Length check at the end is just for brevity so the script returns boolean.)
{
"size": 1,
"query":…

wst
- 4,040
- 4
- 41
- 59
2
votes
1 answer
How to compare field with _id in elasticsearch script?
{
"query":{
"bool":{
"must":{
"match_all":{
}
},
"filter":[
{
"script":{
"source":"doc['id'].value == doc['_id'].value",
…

user12496039
- 47
- 8
2
votes
1 answer
elastic search - update specific nested object
I have hotel documents that each have rooms of nested type.
{
id: hotel_id,
rooms: [
{
id: room_id_1,
name: "room 1 name"
},
{
id: room_id_2,
name: "room 2 name"
},
....
]
}
And I…

Vlad Dogarescu
- 153
- 1
- 11
2
votes
0 answers
score_ in ElasticSearch painless script is always returning 1
I believe that the _score parameter ought to be returning the current relevance score of a document, but in my situation it is always returning 1. It might be related to the use of only custom scoring functions?
This is my JSON query:
{
"query":…

Sam Stickland
- 637
- 1
- 6
- 17
2
votes
1 answer
How to call stored painless script function in elastisearch
I am trying to use an example from
https://www.elastic.co/guide/en/elasticsearch/reference/6.4/modules-scripting-using.html
I have created a function and saved it.
POST http://localhost:9200/_scripts/calculate-score
{
"script": {
"lang":…

Roman
- 21
- 1
- 2
2
votes
1 answer
how to avoid duplicate painless script in elastic-search
I have a elastic query script that meant to calculate the ground distance with the parameters I gave it and I have to use it in multiple queries Is there a way to avoid this duplication , for-example a way to calculate a global variable and use it…

slifer2015
- 682
- 6
- 12
2
votes
2 answers
How to merge range and multi match query in elasticsearch
I have field in elasticsearch doc. Which has date field and two string field.I want to apply range on date and match filter on two string fields.How to apply this?
Let's say I have this doc
movies
{
name :"titanic",
director:"james Cameron",
…

Manoharsinh Rana
- 53
- 2
- 8
2
votes
1 answer
Is is possible to transform JSON data in an Elasticseach Painless script, and perform further operations on it?
We have a large corpus of JSON-formatted documents to search through to find patterns and historical trends. Elasticsearch seems like the perfect fit for this problem. The first trick is that the documents are collections of tens of thousands of…

David Krider
- 886
- 12
- 27
2
votes
1 answer
How to create dictionary object and add data to it in painless elastic search
I want to write a painless script which should return a dictionary.
Basically, If I relate it to java, I want an output of Dictionary< String, List >.
So, I need to declare a Map and List in painless.
Also, I need to add data to it (like…

AbhiArora
- 162
- 1
- 8
2
votes
1 answer
Painless Scripting Kibana 6.4.2 not matching using matcher, but matches using expression conditional
Hello I'm trying to take a substring of a log message using regex in kibana scripted fields. I've run into an interesting scenario that doesn't add up. I converted the message field to a keyword so I could do scripted field operations on it.
When I…

Grant Zukel
- 1,153
- 2
- 24
- 48
2
votes
1 answer
Delete only fields from all the documents that match my criteria
To delete any field with value from all the documents without deleting the whole document from the Elasticsearch index usually I use _update_by_query API call with script
For Ex: on my_properties index I want to delete all the fields e.g…

A l w a y s S u n n y
- 36,497
- 8
- 60
- 103
2
votes
1 answer
Is there a way to convert a date field into a different timezone using Painless language?
Is there a way to convert this code using Painless?
the index have a field named created, and the goal is to convert the value to a different timezone, currently it's in UTC.
"aggregations": {
"dayOfWeek": {
"terms": {
"script":…

Jane S.
- 215
- 1
- 4
- 12