Reputation: 431
We're using Spring Data Elasticsearch with nodes (and replicas) distributed geographically. We'd like to minimize the query traffic across boundaries and have all of the queries performed on the 'local' node. Is there anyway to force this globally? There doesn't seem a way to force it other than switching everything to native queries and throwing out all of our repositories, etc.
Upvotes: 0
Views: 408
Reputation: 41
No need to patch ElasticsearchTemplate, I have fix it in last Spring Data Elasticsearch 3.2
NativeSearchQuery searchQueryWithValidPreference = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
.withPreference("_local").build();
Upvotes: 0
Reputation: 431
I ended up shadow patching Spring Data Elasticsearch's ElasticsearchTemplate class and adding the following line:
private SearchRequestBuilder prepareSearch(Query query) {
//...
searchRequestBuilder.setPreference("_local");
logger.info("----- using shadow patched ElasticsearchTemplate so queries/searches prefer local node -----");
return searchRequestBuilder;
}
Upvotes: 1