Questions tagged [elasticsearch-painless]

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'.

484 questions
2
votes
1 answer

Sorting in Elasticsearch Painless

I had the following line in a groovy script that I'm attempting to rewrite into painless - def buckets = ctx.payload.aggregations.metrics.buckets.sort(a,b -> a.largest_surprise.value == b.largest_surprise.value ? 0 : a.largest_surprise.value <…
Nick
  • 695
  • 8
  • 23
2
votes
1 answer

Elasticsearch Painless script get nested field by value?

I want to compute the score of my query on elasticsearch based on a nested field value. Here is an example of my document: { "title": "Mr", "first_name": "Barry", "last_name": "White", "experiences": [ { "name": "parachute", …
theplayer777
  • 163
  • 1
  • 15
2
votes
1 answer

How do you add an object to an array using scripts in ElasticSearch?

I am trying to add an item to an array in one of my Elastic Search documents. I can do this for simple items, such as strings, but cannot work out now to add objects. Here is my current code: POST /user_profiles/user_profile/12345/_update { …
2
votes
1 answer

Migration from groovy script to painless scriptin ElasticSearch 5.2.1

I have been using a groovy Script as ScriptType.File. A part of my groovy Script looks like this. def refApplicValues =_source.refApplicValue; def lineNumbers = refApplicValues.tokenize('|'); Now Im migrating to ElasticSearch 5.2.1 which uses…
ajain k
  • 21
  • 2
1
vote
1 answer

Elasticsearch painless script compilation error on date field

In my e-commerce project, I was trying to sort the products based on the sale start field and also by the orderingData from the PIM. eg: I have salestart key in the ES document and also we have orderingDatalike(1,2,3,4) In FED(react) we need to…
1
vote
1 answer

Fetching documents with calendarItems.minNights first value greater than 2 using Elasticsearch DSL

I would like to learn how to fetch documents with the first value of the calendarItems.minNights field greater than 2 using Elasticsearch DSL. The data structure looks like this: In the above data structure, I want to retrieve documents where the…
1
vote
0 answers

Condition for custom upsert in Elasticsearch

I use Elasticsearch 6.8.13 and Java SDK for elasticsearch. I try to make custom upsert. The idea is to use Painless script for make a decision to index document or nothing to do. I tried next Painless script: if (condition) { ctx.op = 'noop'; }…
Frofike
  • 321
  • 2
  • 6
1
vote
0 answers

doc.size(), doc.keySet() in painless gives unsupported_operation_exception: null

I am trying to transform a set of documents, and i have a bunch of x.y.a, x.y.b, x.y.c ... etc properties i would like to filter and remap to props.a, props.b It seems like a scripted_metric aggregation is the only way to achieve this. The idea is i…
Pete
  • 11
  • 2
1
vote
1 answer

How to access mapping sub-fields in painless?

Assuming there is an Elasticsearch mapping: "mappings": { "dynamic_templates": [], "properties": { "name": { "type": "text", "fields": { "x": { "type": "completion" …
1
vote
1 answer

How to prevent "Too many dynamic script compilations within" error with search templates?

I use a search template with "mustache" language to build dynamic queries according to different parameters. When I often modify the values ​​of the parameters of this request, I get this error message : [script] Too many dynamic script compilations…
Ricou13
  • 21
  • 5
1
vote
1 answer

Elasticsearch script query started to fail suddenly

We have had this query for a long time { "size": 50, "query": { "match_all": {} }, "version": false, "seq_no_primary_term": false, "sort": [ { "_script": { "script": { "source": "(doc[params.f].size() !=…
Richa
  • 7,419
  • 6
  • 25
  • 34
1
vote
1 answer

ElasticSearch painless filter script on text fields not working

I want to use an equality filter (exact match) using a painless script in ElasticSearch. I cannot use directly a term query because the check I want to do is on a text field (and not keyword), so I tried with a match_phrase. This is my mapping: I…
1
vote
1 answer

How to access java.util.Arrays in painless script (elasticsearch)

I am trying to do a binary search on a huge array (sorted_keys) sorted_keys.length = 250,000 my_script = f""" if (Arrays.binarySearch({sorted_keys}, doc['_meta.key'].value) > 0)) return 0; return 1; """ script =…
Naim Mustafa
  • 314
  • 2
  • 14
1
vote
1 answer

how to send email alert to groups based on condition success in kibana watcher action

I am able to categorize various error like this --- But i want to send email to groups based on error message. Something like --- when error ie "key"= "Response status code does not indicate success Service Unavailable" ---send email to group 1…
1
vote
0 answers

Use a runtime field in decay function elasticsearch

In Elastic I am using a runtime field to calculate a personal price based on user input. The field is defined as a 'double' type and has a Painless script to calculate the price. The output is fine and I can then sort by this runtime field, so up…
Julia
  • 61
  • 4