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
3
votes
0 answers

script_fields always returns array. how to return an object or simple data type?

I noticed that when using script_fields it always returns array of the values that should be returned. I wonder why is this happening and is it possible to just return a non-array data type like an object or bool? Example to illustrate (taken from…
Andrey Borisko
  • 4,511
  • 2
  • 22
  • 31
3
votes
0 answers

How to sort results based on term position in elasticsearch >= 5.5?

Since _index is no longer available in Painless scripting, hence solutions which used to work via accessing term-offset from _index in script_score do not work any more such as one advised here: Scoring by term position in ElasticSearch?. What's the…
virtualmic
  • 3,173
  • 6
  • 26
  • 34
3
votes
1 answer

elasticsearch painless access dynamically named field

I am trying to average a field in elastic search, "aggs": { "avg_timedifference": { "avg": { "script" : "doc['@timestamp'].value" } } this works, where the mapping is, { "_index" :…
JVM
  • 41
  • 2
3
votes
1 answer

Is it possible to access fields of event during logstash scripted_upsert?

Is it possible to access event fields in script of elasticsearch logstash output with scripted_upsert? output { elasticsearch { hosts => ["elasticsearch:9200"] index => "index" document_type => "doctype" action =>…
LosBlancoo
  • 113
  • 10
3
votes
0 answers

how to determine whether a variable is array in Painless, Elasticsearch

I want to remove an element in array, if the field is not array, do nothing. if (ctx._source?.field != null) { ctx._source.field.remove(ctx._source.field.indexOf('value')) } In order to do so, it has to determine whether the field is an array,…
Allen_Tsang
  • 555
  • 1
  • 6
  • 14
3
votes
2 answers

How to replace string without regexp inside Painless inline script for AWS ElasticSearch?

The type of the "level" field in the document was changed from "keyword" to "short" and I'm trying to reindex exist data to be able to use it in Kibana charts. Old data contains values like: "100%", "error" or just empty string "". I want to get…
kivagant
  • 1,849
  • 2
  • 24
  • 33
3
votes
1 answer

elasticsearch mapping for Friend to Friend list

we have started using elasticsearch in our project, we are storing user data and his friend list as nested object, and nested to nested object storing friend's friend list because we required this data when we are doing global search. Now we are…
Deepesh Uniyal
  • 923
  • 3
  • 20
  • 44
3
votes
0 answers

Return value issues with Elasticsearch 5.5 painless script queries return value

I'm using Elasticsearch 5.5 API FunctionScoreQueries with filter. The goal here is to mimic LinearDecayFunction, but because the values that I want to use are contained in the document and not available in my java application, I'm creating my own…
Rlarroque
  • 1,900
  • 1
  • 17
  • 27
3
votes
1 answer

How to distinct rows from list of lists using Painless scripting language?

I have a Groovy script: def results = [] def cluster = ['cluster1', 'cluster1', 'cluster1', 'cluster1', 'cluster1', 'cluster1']; def ports = ['4344', '4344', '4344', '4344', '4344', '4344']; def hostname = […
user2156115
  • 1,169
  • 4
  • 17
  • 30
3
votes
1 answer

SHA1 in painless (elasticsearch)

How I can update SHA1 for a lot of millions records in index? like... { "query": ... "script": "ctx._source.sha1 = sha1(ctx._source.field)" } Painless has not built-in SHA1 function as is as groovy. Do exist a way without using client-side? If I…
RuS
  • 71
  • 7
3
votes
0 answers

Elasticsearch update script - 'noop' flushes entire script

I want to update 2 fields in a document in a single update request, using an inline painless script: { "script" : { "inline": "ctx._source.counter1 ++ ; ctx._source.counter2 == 0 ? ctx.op = 'noop' : ctx._source.counter2 ++"} } Problem…
belostoky
  • 934
  • 2
  • 11
  • 22
3
votes
1 answer

How can I do this in painless script Elasticsearch 5.3

We're trying to replicate this ES plugin https://github.com/MLnick/elasticsearch-vector-scoring. The reason is AWS ES doesn't allow any custom plugin to be installed. The plugin is just doing dot product and cosine similarity so I'm guessing it…
toy
  • 11,711
  • 24
  • 93
  • 176
3
votes
2 answers

ElasticSearch: compute arcDistance from nested field in Painless script

I need to compute an arc distance inside a Painless script, but have not found a way of accessing the geo APIs in this case, i.e: the first point is passed to the script as a param - which means I only get primitive values the second point is read…
3
votes
1 answer

Scripted dynamic update not working in ElasticSearch

I am using the below code to update a document in elasticsearch client.update({ index: 'myindex', type: 'mytype', id: '1', body: { script: 'ctx._source.tags += tag', params: { tag: 'some new tag' } } }, function (error,…
2
votes
2 answers

Pass a dynamic value in the Elasticsearch Painless script params from the Elasticsearch

I am passing params map in the painless script, that map is type of . The key of the map defines the id and the value defines the foundDate in epoch Long. The elastic Document have the raw structure like this : doc:{ [ "id":11406,…