Skip to content

Commit

Permalink
Lookup Terms Filter ignores the routing parameter
Browse files Browse the repository at this point in the history
fixes #3233
  • Loading branch information
kimchy committed Jun 25, 2013
1 parent 84a2445 commit b1968d4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
Expand Up @@ -76,6 +76,7 @@ public Filter parse(QueryParseContext parseContext) throws IOException, QueryPar
String lookupType = null;
String lookupId = null;
String lookupPath = null;
String lookupRouting = null;

CacheKeyFilter.Key cacheKey = null;
XContentParser.Token token;
Expand Down Expand Up @@ -109,6 +110,8 @@ public Filter parse(QueryParseContext parseContext) throws IOException, QueryPar
lookupId = parser.text();
} else if ("path".equals(currentFieldName)) {
lookupPath = parser.text();
} else if ("routing".equals(currentFieldName)) {
lookupRouting = parser.textOrNull();
} else {
throw new QueryParsingException(parseContext.index(), "[terms] filter does not support [" + currentFieldName + "] within lookup element");
}
Expand Down Expand Up @@ -164,7 +167,7 @@ public Filter parse(QueryParseContext parseContext) throws IOException, QueryPar
}

// external lookup, use it
TermsLookup termsLookup = new TermsLookup(fieldMapper, lookupIndex, lookupType, lookupId, lookupPath, parseContext);
TermsLookup termsLookup = new TermsLookup(fieldMapper, lookupIndex, lookupType, lookupId, lookupRouting, lookupPath, parseContext);
if (cacheKey == null) {
cacheKey = new CacheKeyFilter.Key(termsLookup.toString());
}
Expand Down
Expand Up @@ -32,6 +32,7 @@ public class TermsLookupFilterBuilder extends BaseFilterBuilder {
private String lookupIndex;
private String lookupType;
private String lookupId;
private String lookupRouting;
private String lookupPath;

private String cacheKey;
Expand Down Expand Up @@ -81,6 +82,11 @@ public TermsLookupFilterBuilder lookupPath(String lookupPath) {
return this;
}

public TermsLookupFilterBuilder lookupRouting(String lookupRouting) {
this.lookupRouting = lookupRouting;
return this;
}

public TermsLookupFilterBuilder cacheKey(String cacheKey) {
this.cacheKey = cacheKey;
return this;
Expand All @@ -96,6 +102,9 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio
}
builder.field("type", lookupType);
builder.field("id", lookupId);
if (lookupRouting != null) {
builder.field("routing", lookupRouting);
}
builder.field("path", lookupPath);
builder.endObject();

Expand Down
Expand Up @@ -95,7 +95,7 @@ private Filter termsFilter(final CacheKeyFilter.Key cacheKey, final TermsLookup
return cache.get(cacheKey, new Callable<TermsFilterValue>() {
@Override
public TermsFilterValue call() throws Exception {
GetResponse getResponse = client.get(new GetRequest(lookup.getIndex(), lookup.getType(), lookup.getId()).preference("_local")).actionGet();
GetResponse getResponse = client.get(new GetRequest(lookup.getIndex(), lookup.getType(), lookup.getId()).preference("_local").routing(lookup.getRouting())).actionGet();
if (!getResponse.isExists()) {
return NO_TERMS;
}
Expand Down
Expand Up @@ -32,16 +32,18 @@ public class TermsLookup {
private final String index;
private final String type;
private final String id;
private final String routing;
private final String path;

@Nullable
private final QueryParseContext queryParseContext;

public TermsLookup(FieldMapper fieldMapper, String index, String type, String id, String path, @Nullable QueryParseContext queryParseContext) {
public TermsLookup(FieldMapper fieldMapper, String index, String type, String id, String routing, String path, @Nullable QueryParseContext queryParseContext) {
this.fieldMapper = fieldMapper;
this.index = index;
this.type = type;
this.id = id;
this.routing = routing;
this.path = path;
this.queryParseContext = queryParseContext;
}
Expand All @@ -62,6 +64,10 @@ public String getId() {
return id;
}

public String getRouting() {
return this.routing;
}

public String getPath() {
return path;
}
Expand Down

0 comments on commit b1968d4

Please sign in to comment.