Questions tagged [elasticsearch-scripting]

With scripting, you can evaluate custom expressions in Elasticsearch. For example, you could use a script to return "script fields" as part of a search request or evaluate a custom score for a query.

The default scripting language is Painless. Additional lang plugins enable you to run scripts written in other languages. Everywhere a script can be used, you can include a lang parameter to specify the language of the script.

Source: official documentation.

26 questions
2
votes
1 answer

ElasticSearch exact match on text field with script

I'm trying to search with an ElasticSearch query documents that have exactly a certain value in a text field. I know that with a term query it could be possible if it were a keyword field. Unfortunately, I can't change the mapping. { "my_index":…
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":…
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…
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

Elasticsearch: count query in _search script

I'm trying to make a single query for updating the one field value in ES index. I have a index pages which contain information about the pages (id, name, time, parent_page_id, child_count etc) I can update the field parent_page_id with number of…
1
vote
2 answers

Elasticsearch update nested field with painless script in ElasticSearch API vs java API

Could someone explain what's wrong with ES java api? I'm making query to update by script with ES api and it works perfectly (below) POST user/ut/520411_5752/_update { "script": { "source": "ctx._source.cars.add(params.car)", "params": { …
1
vote
1 answer

Return Elasticsearch distance for array of geo points

I need to return the distance for multiple geo points per document in an Elasticsearch array. As of now, my results only return one distance calculated for the array. I started with the code from the following StackOverflow question: Return distance…
1
vote
1 answer

How do I aggregate a bit field in Elasticsearch?

I have a 60-bit (minutes in an hour) field that I would like to aggregate with a bit-wise or operator so that the end result is a bit set if any of the contributing values had that bit set. The representation of the bit field isn't determined yet,…
1
vote
1 answer

Extract date (yyyyMMdd) from date field in ElasticSearch query

My index has a date field formatted as 2020-01-04T05:00:06.870000Z. In the ES query response, I need the date in the form yyyyMMdd, so 20200104. I tried using scripted query and extracted the day, month and year individually. How can i concatenate…
1
vote
1 answer

Aggregations with dynamic data / nested_objects

I'm trying to aggregate over dynamically mapped fields in ElasticSearch. For example: POST test/_doc/1 { "settings": { "range": { "value": 200, "display": "200 km" }, "transmitter": { …
1
vote
0 answers

Scripting in elasticsearch

I have a couple of questions about scripting in elasticsearch, I hope someone can help me. I need to add several parameters from the document to _score and sort by the total value. First, I will describe the data that I have and which need to be…
1
vote
1 answer

Correction of score results

I would like to know if it is possible to implement this in elastic. Let's say I have documents of this structure. { "title": "text1 text2 text3", "score_adj":[ {"text":"text1", "adj": -2}, {"text":"text3", "adj": -4} ] } And I will look for…
0
votes
0 answers

Elasticsearch access fields in a document before matching

I have the following mappings in my elasticsearch index { "test-index" : { "mappings" : { "properties" : { "factor" : { "type" : "long" }, "price_range" : { "type" : "integer_range", …
0
votes
1 answer

How to iterate through aggregation buckets and send mail corresponding to each bucket using watcher action

I am trying to iterate through the aggregation bucket results. The aggregation response is : "aggregations" : { "agg1" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" :…
0
votes
2 answers

ElasticSearch aggregate on a scripted nested field

I have the following mapping in my ElasticSearch index (simplified as the other fields are irrelevant: { "test": { "mappings": { "properties": { "name": { "type": "keyword" }, "entities": { …
1
2