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 Painless script for the average aggregation based on date difference and one of the date is from params maps
I am trying to calculate the average aggregation based on date difference.
Earlier both the date were in the same index, so tired this for the average index:
"avg": {
"script": {
"source": "(doc['lastFixed'] -…

Rushikesh Sabde
- 1,376
- 1
- 8
- 24
2
votes
3 answers
Parse Date from Script_Fields Params
I am trying to find the elapsed time
elapsed time: duration of time b/w now and createdTime
To pass the current_time (ie now) I have added it to the params, and I can access that in the source field by writing params['now']
The problem is that…

Prashant Meena
- 21
- 4
2
votes
2 answers
Is there a way to run sleep command with painless in Elasticsearch 7?
In the old version of Elasticsearch, we can do:
% curl -XPOST 'localhost:9200/online-shop/shirts/1/_update' -d '{
"script": "Thread.sleep(10000); ctx._source.price = 2"
}'
How to do the sleep with painless in Elasticsearch 7?
Index a document…

Q. Qiao
- 767
- 6
- 17
2
votes
1 answer
How to write unit test for Elasticsearch painless scripts using Java
Here is my sample painles script used in Elasticsearch. I want to write a unit test for this. How can I achieve it?
{
"script": {
"source": """
for(param in params.entrySet()) {
ctx.source.put(param.getKey(), param.getValue())
…

Galet
- 5,853
- 21
- 82
- 148
2
votes
2 answers
Change field values using Elasticsearch Painless
I want to check the length of each field under the object alert.
If it's longer than X, change it to value was truncated since it was too long
"_source" : {
"random" : 123455,
},
"@timestamp" :…

Dennis
- 95
- 1
- 1
- 6
2
votes
3 answers
Painless Elasticsearch Script for Filtering Nested Array Objects
My use case is something similar to following.
I have nested array of objects warehouses and trying to filter based on the last element of the array.
I am getting some results but not correct one. Like to know how exactly it is working though as…

aniketk
- 109
- 1
- 7
2
votes
1 answer
Elasticsearch querying documents between two range fields of strings
I have a log file stored in Elasticsearch, where a document is a single line of the file. Blocks of messages start and end with certain keywords. I want to get all documents between documents containing these keywords. Is there a way to leverage the…

Sandesh
- 33
- 3
2
votes
2 answers
elasticsearch node.js API remove an object from an array on a document using painless script results in array Index Out of Bounds
I want to remove items (an object) from an array on a document in elasticsearch, however whenever I try and run my update script using painless, I receive an Array Index Out of Bounds exception.
I'm using the javascript elasticsearch npm package to…

Jarede
- 3,310
- 4
- 44
- 68
2
votes
2 answers
Select documents by array of objects when at least one object doesn't contain necessary field Elasticsearch
I have documents in the elasticsearch and can't understand how to apply search script that should return documents if any attachment doesn't contain uuid or uuid is null. Version of elastic 5.2.
Mapping of documents
"mappings": {
"documentType":…

Stepan Poperechnyi
- 325
- 3
- 18
2
votes
1 answer
How to add between filter on nested script_score?
I'm filtering prices dynamically with the given currency rates and sorting them with the score which is generated by script. But there is one thing I could not figure out how to do is range filter.
For example I only want to get product_platforms…

Strep throat
- 45
- 3
2
votes
0 answers
Elasticsearch bucket script aggregation in Kibana
I am trying to create the visualization in Kibana, to show the number of orders whose average api time is less than 60 Sec. I am able to write the Elasticsearch query with bucket script aggregation.
ES index documents:
order_id time api
1 …

Lakshman Battini
- 1,842
- 11
- 25
2
votes
0 answers
Elasticsearch: How can I access a nested field from a post_filter using painless
I'm facing a challenge using painless in a post filter, what I need is to access a nested field from the painless script, the goal here is to apply the filter base on prices range (these ranges are base on a quoting), and we don't want to lose the…

Juan Sebastian Cortes Torres
- 47
- 1
- 5
2
votes
1 answer
With Elastic Search, how can I index a document containing an array into multiple documents, one per array item?
Suppose I have a JSON document (sent from packetbeat in this case) containing some structure like this:
{
"source": "http://some/url/",
"items": [
{"name":"item1", "value":1},
{"name":"item2", "value":2}
]
}
How can I have Elastic…

phhu
- 1,462
- 13
- 33
2
votes
1 answer
How to get matched field value of array field using painless script in Elasticsearch?
I'm using Elasticsearch 7.6
I have documents in Restaurant index which look like this:
"name" : "ABC restaurant",
"menu" : [
{
"name" : "chicken",
"count" : 23
},
{
"name" : "rice",
"count" : 10 }
…

mappy
- 367
- 5
- 19
2
votes
2 answers
Elasticsearch pre-processing to remove null fields as part of ingest
I have a use case where an API i'm calling to retrieve data to put into elasticsearch is returning nulls.
I need to write an ingest pipeline that uses processors to remove all null fields before writing it into elasticsearch. Processors may or may…

raja
- 61
- 8