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
1
vote
1 answer
Retrieve information of last element of an array painless-ly in elasticsearch
While updating a doc (using update API), I need to extract a field of last entered element of an array, and then use it while adding a new element to the same array.
For example:
{
"_id": "guid",
"timestamp": "time",
"conversation": [
{
…

AbhiArora
- 162
- 1
- 8
1
vote
1 answer
How to sort multiple fields with exception condition
I cannot use FieldSortBuilder to sort by multiple fields and do the exception condition. So I am wondering can we use painless to do it?
Below is data model.
{ "name" : "string",
"email" : "string",
"schoolNumber" : "number",
"startTime" :…

Lena
- 41
- 2
- 4
1
vote
1 answer
Aggregations on nested documents with painless scripting
USING ELASTIC SEARCH 6.2
So I have a deeply nested document structure which has all the proper mapping (nested, text, keyword, etc). A sample document is as follows:
{
"type": "Certain Type",
"lineItems": [
{
"lineValue":…

Anirudh Kanabar
- 28
- 5
1
vote
1 answer
How to search substring from log field using the scripted fields in painless without regex
I am trying to create to some scripted fields using painless by capturing some "keyword" in the log field, which is a long text field. for example, I have bunch of the log fields:
"Error: Duplicate entry in user1"
"Error: Duplicate entry in…

Akira
- 273
- 5
- 15
1
vote
1 answer
[es painless]difference between doc and params._source
when use doc["abc"],it turns out no field "abc" exception, only to find params._source["abc"] get everything correct.
I checked the status of doc["abc"].value ,it shows null , also doc["abc"].empty is true.
1.elasticsearch version:5.x
2.use painless…

zzzhy
- 13
- 1
- 4
1
vote
0 answers
In Elasticsearch, how can I apply a timezone to "source": "doc['date'].value.dayOfWeek"
{
"size": 0,
"aggs": {
"messages_per_channel": {
"terms": {
"field": "channelId"
},
"aggs": {
"total_messages_per_day_of_week": {
"terms": {
"script": {
"lang":…

Sritzl
- 11
- 2
1
vote
0 answers
Remove large object from list in Elasticsearch doc based on an object value
In ES 6, I have indexed the following doc:
PUT test/doc/_bulk?refresh
{"index":{"_id":1}}
{"prop1":"foo","prop2":[{"a":"123"},{"a":"456"}]}
I need to remove the element from "prop2" that has a value of "456" for "a"
The remove() method in Painless…

kgeo
- 412
- 5
- 19
1
vote
1 answer
Check value exists in params array using ElasticSearch painless script
I am new to ElasticSearch. I am working on a project where I have to search listings which matches the input http://foo.bar/search?listing=123,456. I have built an array which key and value are the same and representing the listing ids. I have tried…

CEJ
- 131
- 5
- 14
1
vote
1 answer
How to get the current entry of a foreach pipeline instruction using painless scripting?
I am trying to count JSON objects based on a flag.
To do so, I created two foreach pipelines iterating over my objects.
I want to count all the objects in the documents array for which the field "count" is set to true.
POST…

Louis
- 1,913
- 2
- 28
- 41
1
vote
1 answer
elasticsearch painless combination with key of aggregation and its nested aggregation key
Working on a transform for elasticsearch query result
{
'key': factoryA,
'buckets': [
{
'key': 'productX'
}
]
},
{
'key': factoryB,
'buckets': [
{
'key': 'productX'
},
{
…

perigee
- 9,438
- 11
- 31
- 35
1
vote
1 answer
Script writing to get Distinct value from Elasticsearch
I want to create a custom distinct function where I can write simple distinctBy script of multiple field names to be distinct together. So is there anyway in ElasticSearch to achieve this.

Jawadh Salih Rifath
- 150
- 1
- 8
1
vote
1 answer
How to get timestamp from date in elastic search script
As the title suggests, I want to get the timestamp (as a number) from a date type in an elastic search painless script. The following attempts didn't work: doc["date_field"].value, doc["date_field"].date.getMillis().

Murukan
- 189
- 1
- 4
- 15
1
vote
1 answer
Elasticsearch term aggregation using script with key as integer
Is it possible to make the key of the resulting aggregation be the int value returned by the script instead of a string?
See this example, but using dayOfMonth or hourOfDay instead of dayOfWeek, so there are more than 10 values, so the result ends…

Dave Johansen
- 889
- 1
- 7
- 23
1
vote
2 answers
Updating collection items in Java
I'm trying to do partial update on collection items based on a condition. Here's the Java code snippet:
public class Point {
public int x = 0;
public int y = 0;
public Point(int a, int b) {
x = a;
y = b;
}
…

mohi666
- 6,842
- 9
- 45
- 51
1
vote
1 answer
Get count of data while search operation on front end
This is the sample object how my data is stored in an index.
{
_index: "crawled_websites",
_type: "crawled_websites",
_id: "1I4ZGGUBSEHPBwjchC_2",
_score: null,
_source: {
url: "https://ewn.co.za/Topic/Patricia-de-Lille",
description: "EWN - South…

Er Samir Mirani
- 13
- 4