elasticsearch-painless

Painless scripting Elastic Search : variable is not defined error when trying to access values from doc

寵の児 提交于 2019-12-24 07:58:55
问题 I am trying to learn painless scripting in Elastic Search by following the official documentation. ( https://www.elastic.co/guide/en/elasticsearch/painless/6.0/painless-examples.html ) A sample of the document I am working with : { "uid" : "CT6716617", "old_username" : "xyz", "new_username" : "abc" } the following script fields query using params._source to access document values works : { "script_fields": { "sales_price": { "script": { "lang": "painless", "source": "(params._source.old

NullPointerExceptions when accessing ElasticSearch painless scripted metric aggregation params

落花浮王杯 提交于 2019-12-24 05:56:30
问题 When accessing doc within map_script of a scripted aggregation, I keep getting a null pointer exception. For { "init_script":{ "source":"params._agg['transactions'] = [];" }, "map_script":{ "source":"Debug.explain(params)" <---------------- }, ... } I get { ..., "painless_class":"java.util.HashMap", "to_string":"{doc=org.elasticsearch.search.lookup.LeafDocLookup@133b9d24, _source=org.elasticsearch.search.lookup.SourceLookup@7b812d13, _doc=org.elasticsearch.search.lookup.LeafDocLookup@133b9d24

Elasticsearch Painless calculate score from nested elements

自作多情 提交于 2019-12-21 17:40:06
问题 Note: I had originally posted this question a little differently and it wasn't worth updating as after reading I learned a bit more. Requirement Search for documents and calculate a custom score based on nested elements within the document. Structure { "mappings": { "book": { "properties": { "title": { "type": "string", "index": "not_analyzed" }, "topics": { "type": "nested", "properties": { "title": { "type": "string", "index": "not_analyzed" }, "weight": { "type": "int" } } } } } } } Sample

How to write query to find percentage in elasticsearch?

南笙酒味 提交于 2019-12-13 20:17:29
问题 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 have store_id, range of dates and event type in the input.in output, I need the percentage amount of time device was online for that hour. This is how we consider device online. If there is an event="heartbeat" for a store_id in an hour then we say the store

How to convert binary data back to a float array in Elasticsearch/painless

只愿长相守 提交于 2019-12-11 17:16:39
问题 I am trying to efficiently store and retrieve an array of floats in elasticsearch 6.7. Numeroc doc values are sorted, which means I can't use them directly. At first I was using the source value of the field, but the performance on a large query is not great. I tried to encode the float array as binary and decode it inside my script. Unfortunately I'm stuck at converting a byte[4] array to a float in painless . In Java this would look like this Float.intBitsToFloat((vector_bytes[3] << 24) | (

Elasticsearch search query: why params._source.nested_field.size() is not working in script?

柔情痞子 提交于 2019-12-11 07:23:37
问题 There are lot of questions and answers about this but still didn't get a satisfied answers. Elasticsearch version: 6.5 Index mapping "_doc": { "properties": { "ssid": { "type": "long" }, "nested_field": { "type": "nested" } } } } Search query: { "query": { "bool": { "filter": { "script": { "script": "params._source.nested_field.size() > 1" } } } } } Also tried below query but no luck { "query": { "bool": { "must": [ { "nested": { "path": "nested_field", "query": { "bool": { "filter": {

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

删除回忆录丶 提交于 2019-12-10 21:55:05
问题 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 preferred way to do this now? Thanks much for your help! 来源: https://stackoverflow.com/questions/49304331/how-to-sort-results-based-on-term-position-in-elasticsearch-5-5

ElasticSearch/Painless: How do I access/sum all values in an object

邮差的信 提交于 2019-12-06 15:14:52
I've been looking at aggregations, and at scripting using painless , and I am not able to figure out how to iterate/sum over all values in an object. Example: My mapping looks like "field1": { "properties": { "subfield1": { "type": "float" }, "subfield2": { "type": "float" }, "subfield3": { "type": "float" } } } Let's assume my data looks like this: { "field1" : { "subfield1": 50.0, "subfield2": 20.5, "subfield3": 30.5 } } I want to perform a range query on 50.0 + 20.5 + 30.5 , or, basically, access all the values within the field1 object in some way. Aggregations do not allow me to use wild

How can I do this in painless script Elasticsearch 5.3

こ雲淡風輕ζ 提交于 2019-12-06 12:00:28
问题 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 should be really simple to replicate that in painless script. It looks like groovy scripting is deprecated in 5.0. Here's the source code of the plugin. /** * @param params index that a scored are placed in this parameter. Initialize them here. */

In Elasticsearch, how can I apply a timezone to a scripted date operation?

北慕城南 提交于 2019-12-06 06:00:32
问题 With the aggregation below and using ES5, I'd like to get the dayOfWeek & hourOfDay based on a given timezone (supplied as an identifier from the TZ database). How can I edit "doc['created'].date.dayOfWeek' to adjust for the offset? aggs: { dayOfWeek: { terms: { script: { inline: "doc['created'].date.dayOfWeek", lang: 'painless', }, }, aggs: { hourOfDay: { terms: { script: { inline: "doc['created'].date.hourOfDay", lang: 'painless', }, }, }, }, }, }, 回答1: Something like this should work: {