Native scoring script: iterate over indexed terms of a field


I'm trying to calculate a metric distance using a native scoring script on
my Elasticsearch matches between my query string terms and the found field
term terms of my indexed field.
Therefore I have to retrieve all the indexed field terms.

But it seems to me than I can just get them separately and only by index
of the actual term which I don not know if certain term it not present in
my query string:

This is the method to retrieve the terms separately. I have not seen
another one

Method get() from class IndexField:

public IndexFieldTerm get(Object key, int flags) { String termString = (
String) key;
IndexFieldTerm indexFieldTerm = terms.get(termString);
// see if we initialized already...
if (indexFieldTerm == null) {
indexFieldTerm = new IndexFieldTerm(termString, fieldName,
indexLookup, flags);
terms.put(termString, indexFieldTerm);
return indexFieldTerm;

So is there any way to retrieve all the terms and iterate over them?
The groovy plugin provides this possibility, but I like to use a native
, because it's faster.

Or is my approach simply not very good and there is a much easier way to
calculate my own metric distance?

Moreover I like to know if there is a way to calculate the base score
without using the tf and idf.
I know there is a constant_score query, which provides this option, but
the score is always 1, regardless of the number of term occurences.

I cannot use the way proposed over here:
I just have too many terms.

I hope there is someone who can answer my questions.
Thank you!

You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
For more options, visit