I have the following query which works well with a REST client and returns 3 random results, which is great.
{
"size":3,
"query": {
"function_score": {
"functions": [
{
"filter": { "terms": { "text": ["flu", "influenza"] }},
"weight": 1
},
{
"random_score": {
"seed": "1331"
}
}
]
}
}
}
Now I try to do the same in Java:
FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder();
functionScoreQueryBuilder.add(new TermsQueryBuilder(samplingField, terms), new WeightBuilder().setWeight(1));
functionScoreQueryBuilder.add(new RandomScoreFunctionBuilder());
SearchRequestBuilder builder = client.prepareSearch(collection).setTypes(collection).setSize(3);
builder.setQuery(functionScoreQueryBuilder);
builder.addField("text");
And this query fails with a Data too large exception. I had a look into the code and it seems that the Java client is trying to load all the data into memory and then try to apply the size restriction. Is there any work around that?