Speed up custom search query

Hello, in one of my application I need to match colors to find the closest
one. Each document has several colors in Lab. I choose to write
customScoreQuery and calculate score based on square root of SUM of deltas
of the Lab numbers of the colors. Everything works fine, except the query
is running very slow. I have millions of the documents, and it is
ever-growing document base. So every day the query is slower and slower.
What could be done to improve the performance? May be there is another way
to make such searches, using something else besides Custom Score Queries?
QueryBuilders.customScoreQuery(
QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), fb))
.script("res=0; " +
"for(entry:_source.colors){ " +
"rt=sqrt(" +
"pow(entry.colorL-l, 2)" +
"+pow(entry.colorA-a, 2)" +
"+pow(entry.colorB-b, 2)); " +
"if(rt==0){rt=0.000001};"+
"col=entry.area/rt;"+
"if(col>res){res=col};" +
"} res")
.param("l", lab[0])
.param("a", lab[1])
.param("b", lab[2])

I'd appreciate any ideas or comments.

Thank you,

Eugene

--
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 elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.