Merge remote-tracking branch 'upstream/master' into feature-suggest-refactoring
This commit is contained in:
commit
f527a034a3
|
@ -35,6 +35,7 @@ import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@ -94,8 +95,8 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
|
||||||
validationException = addValidationError("mapping source is empty", validationException);
|
validationException = addValidationError("mapping source is empty", validationException);
|
||||||
}
|
}
|
||||||
if (concreteIndex != null && (indices != null && indices.length > 0)) {
|
if (concreteIndex != null && (indices != null && indices.length > 0)) {
|
||||||
validationException = addValidationError("either concreteIndices or unresolved indices can be set concrete: [" + concreteIndex
|
validationException = addValidationError("either concrete index or unresolved indices can be set, concrete index: ["
|
||||||
+ "] and indices: " + indices , validationException);
|
+ concreteIndex + "] and indices: " + Arrays.asList(indices) , validationException);
|
||||||
}
|
}
|
||||||
return validationException;
|
return validationException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,8 @@ public class PutMappingRequestTests extends ESTestCase {
|
||||||
r.setConcreteIndex(new Index("foo", "bar"));
|
r.setConcreteIndex(new Index("foo", "bar"));
|
||||||
ex = r.validate();
|
ex = r.validate();
|
||||||
assertNotNull("source validation should fail", ex);
|
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];");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,14 +112,16 @@ class ExpressionSearchScript implements SearchScript {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNextVar(String name, Object value) {
|
public void setNextVar(String name, Object value) {
|
||||||
assert(specialValue != null);
|
|
||||||
// this should only be used for the special "_value" variable used in aggregations
|
// this should only be used for the special "_value" variable used in aggregations
|
||||||
assert(name.equals("_value"));
|
assert(name.equals("_value"));
|
||||||
|
|
||||||
if (value instanceof Number) {
|
// _value isn't used in script if specialValue == null
|
||||||
specialValue.setValue(((Number)value).doubleValue());
|
if (specialValue != null) {
|
||||||
} else {
|
if (value instanceof Number) {
|
||||||
throw new ScriptException("Cannot use expression with text variable using " + compiledScript);
|
specialValue.setValue(((Number)value).doubleValue());
|
||||||
|
} else {
|
||||||
|
throw new ScriptException("Cannot use expression with text variable using " + compiledScript);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -383,7 +383,11 @@ public class MoreExpressionTests extends ESIntegTestCase {
|
||||||
.script(new Script("_value * 3", ScriptType.INLINE, ExpressionScriptEngineService.NAME, null)))
|
.script(new Script("_value * 3", ScriptType.INLINE, ExpressionScriptEngineService.NAME, null)))
|
||||||
.addAggregation(
|
.addAggregation(
|
||||||
AggregationBuilders.stats("double_agg").field("y")
|
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();
|
SearchResponse rsp = req.get();
|
||||||
assertEquals(3, rsp.getHits().getTotalHits());
|
assertEquals(3, rsp.getHits().getTotalHits());
|
||||||
|
@ -395,6 +399,11 @@ public class MoreExpressionTests extends ESIntegTestCase {
|
||||||
stats = rsp.getAggregations().get("double_agg");
|
stats = rsp.getAggregations().get("double_agg");
|
||||||
assertEquals(0.7, stats.getMax(), 0.0001);
|
assertEquals(0.7, stats.getMax(), 0.0001);
|
||||||
assertEquals(0.1, stats.getMin(), 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 {
|
public void testStringSpecialValueVariable() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue