#744 - ElasticSearch - isEmpty() expression needs to have outer not:{} negation to work as per ..

This commit is contained in:
Robin Bygrave
2016-06-20 21:32:05 +12:00
parent 3477f590dd
commit d12e55c20b
2 changed files with 34 additions and 1 deletions
@@ -157,4 +157,14 @@ public interface DocQueryContext {
* End nested path expressions.
*/
void endNested() throws IOException;
/**
* Start a not wrapping an expression.
*/
void startNot() throws IOException;
/**
* End a not wrapper.
*/
void endNot() throws IOException;
}
@@ -16,15 +16,38 @@ class IsEmptyExpression extends AbstractExpression {
private final String propertyPath;
private String nestedPath;
IsEmptyExpression(String propertyName, boolean empty) {
super(propertyName);
this.empty = empty;
this.propertyPath = SplitName.split(propertyName)[0];
}
@Override
public String nestedPath(BeanDescriptor<?> desc) {
if (empty) {
// capture the nestedPath as we want to put wrap
// a NOT around the outer of the nested path exists
this.nestedPath = propertyNestedPath(propName, desc);
return null;
} else {
return super.nestedPath(desc);
}
}
@Override
public void writeDocQuery(DocQueryContext context) throws IOException {
context.writeExists(!empty, propName);
if (nestedPath == null) {
context.writeExists(!empty, propName);
} else {
// wrap NOT around the outside of nested path exists expression
context.startNot();
context.startNested(nestedPath);
context.writeExists(empty, propName);
context.endNested();
context.endNot();
}
}
public final String getPropName() {