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
0
votes
1 answer

Unable to use painless in elasticsearch query

I have the following query, which is using painless script to create a script_score, which is used for sorting. Following are my creation scripts - PUT /listings/_doc/1 { "prod_id" : 1, "currency" : "USD", "price" : 1 } PUT…
Dev1ce
  • 5,390
  • 17
  • 90
  • 150
0
votes
1 answer

Empty ctx._source variable when running script

In elasticsearch head I run query for retriving some aggregations. To do it, I need to get some infos from ctx variable. In my script when I try to use: ctx._source I get nullPointerException. "aggregations": { "fieldId": { "terms": { …
0
votes
1 answer

Kibana - log analysis - find unique transaction number

I have a EFK setup to centrally store and query logs of all the application services. There are some services that process events from messages. I want to query how many unique events (transaction-number: UUID) has failed per service, considering…
vvra
  • 2,832
  • 5
  • 38
  • 82
0
votes
1 answer

doc['field'].value never returning values

Using Kibana/ Elasticsearch version 6.6. Trying to run the below simple painless script: String val = "Vanished"; if(doc.containsKey('type')) { return doc['type'].value; } return val; In the Preview Results section, when I try to run the…
0
votes
1 answer

How to write query to find percentage in elasticsearch?

I have data in elasticsearch. this is my actual doc https://docs.google.com/document/d/1DKID90I9ulUcut-S8UfrnSjY-3citEwmyfnJJmrIRU8/edit?usp=sharing doc: { store_id:"abc", event_timestamp:"2019-06-05 13:00:05", event_type:"heartbeat" } I…
0
votes
1 answer

Access nested objects in Elasticsearch using a script

I'm trying to use data from ElasticSearch 6 results in setting up the scoring for my results. Part of my mapping looks like: { "properties": { "annotation_date": { "type": "date" }, "annotation_date_time": { …
Boyos123
  • 119
  • 1
  • 5
0
votes
3 answers

Elasticsearch - bring documents with distinct values to the top of results

So lets say for example I have a 'books' index and each book has an author_id. Because there's only a few authors, author ids will repeat frequently across the books. Books in my index would look something like this: { "title": "Elasticsearch…
Dioralop
  • 165
  • 1
  • 9
0
votes
1 answer

Convert date to year-month-day format with Painless

I have dates in this format: 2018-07-24T08:27:59.259Z. What is the best way to convert this to 2018-07-24 in Painless? Looking through the Painless API reference, I realise there are methods such as getYear(), getMonth() and getDayOfMonth(), but I…
user10400458
0
votes
1 answer

Elastic search advanced query for showing price changes on time series indexes

I have separated my time-series data into day wise indexes. Let's say I have 2 days indexes. 1) index1 data-timeseries-14-04-2019 : example data: {{"_id": 1, "product_name": "mobile1", "product_id": "12145", "created_at": "2014-04-14", …
0
votes
1 answer

access query value from function_score to compute new score

I need to customize ES score. The score function I need to implement is: score = len(document_term) - len(query_term) For instance, one of my document in the ES index is : { "name": "foobar" } And the search query { "query": { …
cylon86
  • 550
  • 4
  • 20
0
votes
1 answer

Reindex Elasticsearch converting unixtime to date

I have an Elasticsearch index which uses the @timestamp field to store the date in a date field. There are many records which are missing the @timestamp field, but have a timestamp field containing a unix timestamp. (Generated from PHP, so seconds,…
Coder1
  • 13,139
  • 15
  • 59
  • 89
0
votes
1 answer

Elasticsearch script: failed to add a new array

I'm trying to add a new array field into a document with painless script but failed. Here is the document to be updated "_source": { "a": {} } I want to add a new array b under a. So I have this script { "script": { "source":…
Jeff
  • 267
  • 5
  • 20
0
votes
0 answers

Elasticsearch UpdateByQuery Generate Random UUID with painless

My ES version is 6.0.0. I am trying to generate a random UUID via an update by query script. Painless simply is refusing to cooperate. Taken from their official docs:…
etudor
  • 1,183
  • 1
  • 11
  • 19
0
votes
1 answer

How do I create a scripted field for the number of values in a piece of data?

I am gathering data in Elasticsearch and visualizing in Kibana. My data contains a variable number of fields for each entry, and I am looking to generate a histogram tracking the number of fields for each entry. For example here are two of my pieces…
0
votes
1 answer

Using Elasticsearch and painless, how do I insert a map array?

I have the following code: "script": { "lang": "painless", "source": """ ctx._source.maparray = [ "first" : "Foo", "last" : "Bar" ] which results in "maparray": { "last": "Bar", "first": "Foo" }, But I want maparray to…
Mary
  • 1,005
  • 2
  • 18
  • 37