Using JavaScript in Elasticsearch

(Ehsan Rezaei) #1

i want to use javaScript in elasticsearch

but I have a problem...
I need to use javascript library. for example:

ctx._source.num = msgpack.encode({foo: "bar"});

not working :frowning2:
how can this be possible?

(Nik Everett) #2

require hasn't been supported and lang-javascript is deprecated in 5.x and will be removed in 6.0 so I don't expect it'll ever be supported. Since none of the languages you can embed in the JVM have working of security or ability to limit execute time we built our own. At this point we're advising everyone to use lang-painless because it has those things. It is still new and rough around the edges but it isn't fundamentally broken for our use case.

(Ehsan Rezaei) #3

Thank you

MessagePack is supported by over 50 programming languages and environments.

Is it possible to use msgpack in Painless scripting?
fore example:
"script" : {
"lang": "painless",
"inline": "MessagePack msgpack = new MessagePack(); ctx._source= msgpack .unpack(ctx._source.num)",
"params" : {
"factor" : 4

(Nik Everett) #4

Possible but fairly unlikely. For the most part we recommend folks store data in JSON so it works well with Elasticsearch. If you don't want fields to be indexed for search you can set "index": false on them and you can turn off doc values with "doc_values": false. At that point Elasticsearch pretty much just stores the field in the _source json and ignores it. I expect MessagePack would save a bit of space but not much on disk because _source is compressed in blocks with other source documents.

(Jörg Prante) #5

What I try to read through the lines is that your intention is to implement a JSON binary compression mechanism.

Note that this is not possible by scripting. You'd have to dig deeper. Technically, Elasticsearch already uses JSON binary compression under the hood The use of SMILE is internal and triggered automatically.

I understand that many HTTP client do not/can not make use of SMILE because it's a Java API feature. To add blindly another binary compression on top of SMILE just for docs with inline scripts adds significant load on Elasticsearch cluster nodes.

Instead, you would have to examine the XContent API and replace SMILE by your codec, so all server nodes and client nodes could speak the same serialization language. This is even more than an ordinary Elasticsearch plugin could do, you'd have to exchange the transport layer. I hardly can see any justification of such a replacement.

For a comparison of SMILE against MessagePack, see

Note, in that context, that Elasticsearch did once support Thrift as an optional node protocol beside compressed JSON but that project had been stopped because benefit is too low.

(system) #6

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.