Skip to content

Commit

Permalink
terms lookup filter builder cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul Anishetty committed Jun 28, 2017
1 parent e738014 commit e0755c6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.4.1-rest-1.0.71</version>
<version>1.4.1-rest-1.0.72</version>
<packaging>jar</packaging>
<description>Elasticsearch - Open Source, Distributed, RESTful Search Engine</description>
<inceptionYear>2009</inceptionYear>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.Version;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.xcontent.ToXContentUtils;
import org.elasticsearch.common.xcontent.XContentBuilder;

Expand Down Expand Up @@ -111,6 +112,7 @@ public TermsLookupFilterBuilder cacheKey(String cacheKey) {
@Override
public void doXContent(XContentBuilder builder, Params params) throws IOException {
if (ToXContentUtils.getVersionFromParams(params).onOrAfter(Version.V_5_0_0) && BooleanUtils.isTrue(cache) && StringUtils.isNotBlank(cacheKey)) {
// doing it this way as query response gets cached and query builder gets cached as well.
BoolFilterBuilder boolFilter = FilterBuilders.boolFilter().must(this).cache(true).cacheKey(cacheKey);
doCopyingCacheKey(builder, params, boolFilter);
} else {
Expand All @@ -120,14 +122,11 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio

private void doCopyingCacheKey(XContentBuilder builder, Params params, BoolFilterBuilder boolFilter) throws IOException {
boolean cacheCopy = cache;
String cacheKeyCopy = cacheKey;
cache = null; // avoid recursion
cacheKey = null;
try {
boolFilter.doXContent(builder, params);
} finally {
this.cache = cacheCopy;
this.cacheKey = cacheKeyCopy;
}
}

Expand All @@ -147,6 +146,12 @@ private void doLookupXContent(XContentBuilder builder, Params params) throws IOE
builder.field("cache", lookupCache);
}
builder.field("path", lookupPath);

if (Strings.hasLength(cacheKey) && ToXContentUtils.getVersionFromParams(params).onOrAfter(Version.V_5_0_0)) {
// cache key support for es5 terms lookup
builder.field("_cache_key", cacheKey);
}

builder.endObject();

if (filterName != null) {
Expand Down

0 comments on commit e0755c6

Please sign in to comment.