Merge remote-tracking branch 'upstream/master' into feature-suggest-refactoring

This commit is contained in:
Ali Beyad 2016-03-14 17:25:02 -04:00
commit f527a034a3
4 changed files with 23 additions and 9 deletions

View File

@ -35,6 +35,7 @@ import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.Index;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
@ -94,8 +95,8 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
validationException = addValidationError("mapping source is empty", validationException);
}
if (concreteIndex != null && (indices != null && indices.length > 0)) {
validationException = addValidationError("either concreteIndices or unresolved indices can be set concrete: [" + concreteIndex
+ "] and indices: " + indices , validationException);
validationException = addValidationError("either concrete index or unresolved indices can be set, concrete index: ["
+ concreteIndex + "] and indices: " + Arrays.asList(indices) , validationException);
}
return validationException;
}

View File

@ -53,6 +53,8 @@ public class PutMappingRequestTests extends ESTestCase {
r.setConcreteIndex(new Index("foo", "bar"));
ex = r.validate();
assertNotNull("source validation should fail", ex);
assertTrue(ex.getMessage().contains("either concreteIndices or unresolved indices can be set"));
assertEquals(ex.getMessage(),
"Validation Failed: 1: either concrete index or unresolved indices can be set," +
" concrete index: [[foo/bar]] and indices: [myindex];");
}
}

View File

@ -112,14 +112,16 @@ class ExpressionSearchScript implements SearchScript {
@Override
public void setNextVar(String name, Object value) {
assert(specialValue != null);
// this should only be used for the special "_value" variable used in aggregations
assert(name.equals("_value"));
if (value instanceof Number) {
specialValue.setValue(((Number)value).doubleValue());
} else {
throw new ScriptException("Cannot use expression with text variable using " + compiledScript);
// _value isn't used in script if specialValue == null
if (specialValue != null) {
if (value instanceof Number) {
specialValue.setValue(((Number)value).doubleValue());
} else {
throw new ScriptException("Cannot use expression with text variable using " + compiledScript);
}
}
}
};

View File

@ -383,7 +383,11 @@ public class MoreExpressionTests extends ESIntegTestCase {
.script(new Script("_value * 3", ScriptType.INLINE, ExpressionScriptEngineService.NAME, null)))
.addAggregation(
AggregationBuilders.stats("double_agg").field("y")
.script(new Script("_value - 1.1", ScriptType.INLINE, ExpressionScriptEngineService.NAME, null)));
.script(new Script("_value - 1.1", ScriptType.INLINE, ExpressionScriptEngineService.NAME, null)))
.addAggregation(
AggregationBuilders.stats("const_agg").field("x") // specifically to test a script w/o _value
.script(new Script("3.0", ScriptType.INLINE, ExpressionScriptEngineService.NAME, null))
);
SearchResponse rsp = req.get();
assertEquals(3, rsp.getHits().getTotalHits());
@ -395,6 +399,11 @@ public class MoreExpressionTests extends ESIntegTestCase {
stats = rsp.getAggregations().get("double_agg");
assertEquals(0.7, stats.getMax(), 0.0001);
assertEquals(0.1, stats.getMin(), 0.0001);
stats = rsp.getAggregations().get("const_agg");
assertThat(stats.getMax(), equalTo(3.0));
assertThat(stats.getMin(), equalTo(3.0));
assertThat(stats.getAvg(), equalTo(3.0));
}
public void testStringSpecialValueVariable() throws Exception {