Is it possible to use lucene expressions in elasticsearch scripts to use tfidf similarities of specific fields as a part of custom scoring function

I want to build custom Elasticsearch scoring function and see that combines TF-IDF similarities of some document fields with relative given parameters with the help. As Elasticsearch scripts provide access to some Lucene functionality with Lucene expressions language, I hope it's possible to use Lucene implementation of a TF-IDF.

Unfortunately, I see almost no documentation and examples for lucene expression scripts for scoring functions. Is it possible? And how?

This won't be possible in expressions; they only have access to the fields of a document and parameters, along with a few static helper functions. You would need to write a native java script. See the advanced scripting example in our docs.

@rjernst Thank you for response. I am actually implementing it on painless. It's feasible (though not convenient). Do you see any advantage to implement it on Java (especially from time performance point of view)?