required _routing fails when path points to an integer field, closes #1357.
This commit is contained in:
parent
d954a93d9d
commit
9d9133a451
|
@ -307,5 +307,9 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String numericAsString() {
|
||||||
|
return Byte.toString(number);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -308,5 +308,9 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String numericAsString() {
|
||||||
|
return Double.toString(number);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -304,5 +304,9 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String numericAsString() {
|
||||||
|
return Float.toString(number);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -308,5 +308,9 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String numericAsString() {
|
||||||
|
return Integer.toString(number);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -307,5 +307,9 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String numericAsString() {
|
||||||
|
return Long.toString(number);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -248,5 +248,7 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
||||||
@Override public Reader readerValue() {
|
@Override public Reader readerValue() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract String numericAsString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -307,5 +307,9 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String numericAsString() {
|
||||||
|
return Short.toString(number);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -33,6 +33,7 @@ import org.elasticsearch.index.mapper.MergeMappingException;
|
||||||
import org.elasticsearch.index.mapper.ParseContext;
|
import org.elasticsearch.index.mapper.ParseContext;
|
||||||
import org.elasticsearch.index.mapper.RootMapper;
|
import org.elasticsearch.index.mapper.RootMapper;
|
||||||
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
|
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
|
||||||
|
import org.elasticsearch.index.mapper.core.NumberFieldMapper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -156,10 +157,23 @@ public class RoutingFieldMapper extends AbstractFieldMapper<String> implements I
|
||||||
String routing = context.sourceToParse().routing();
|
String routing = context.sourceToParse().routing();
|
||||||
if (path != null && routing != null) {
|
if (path != null && routing != null) {
|
||||||
// we have a path, check if we can validate we have the same routing value as the one in the doc...
|
// we have a path, check if we can validate we have the same routing value as the one in the doc...
|
||||||
String value = context.doc().get(path);
|
String value = null;
|
||||||
|
Fieldable field = context.doc().getFieldable(path);
|
||||||
|
if (field != null) {
|
||||||
|
value = field.stringValue();
|
||||||
|
if (value == null) {
|
||||||
|
// maybe its a numeric field...
|
||||||
|
if (field instanceof NumberFieldMapper.CustomNumericField) {
|
||||||
|
value = ((NumberFieldMapper.CustomNumericField) field).numericAsString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
value = context.ignoredValue(path);
|
value = context.ignoredValue(path);
|
||||||
}
|
}
|
||||||
|
if (value == null) {
|
||||||
|
// maybe its a numeric field
|
||||||
|
}
|
||||||
if (!routing.equals(value)) {
|
if (!routing.equals(value)) {
|
||||||
throw new MapperParsingException("External routing [" + routing + "] and document path routing [" + value + "] mismatch");
|
throw new MapperParsingException("External routing [" + routing + "] and document path routing [" + value + "] mismatch");
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,4 +300,28 @@ public class SimpleRoutingTests extends AbstractNodesTests {
|
||||||
assertThat(client.prepareGet("test", "type1", "1").setRouting("0").execute().actionGet().exists(), equalTo(true));
|
assertThat(client.prepareGet("test", "type1", "1").setRouting("0").execute().actionGet().exists(), equalTo(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test public void testRequiredRoutingWithPathNumericType() throws Exception {
|
||||||
|
client.admin().indices().prepareDelete().execute().actionGet();
|
||||||
|
|
||||||
|
client.admin().indices().prepareCreate("test")
|
||||||
|
.addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1")
|
||||||
|
.startObject("_routing").field("required", true).field("path", "routing_field").endObject()
|
||||||
|
.endObject().endObject())
|
||||||
|
.execute().actionGet();
|
||||||
|
client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
|
||||||
|
|
||||||
|
logger.info("--> indexing with id [1], and routing [0]");
|
||||||
|
client.prepareIndex("test", "type1", "1").setSource("field", "value1", "routing_field", 0).execute().actionGet();
|
||||||
|
client.admin().indices().prepareRefresh().execute().actionGet();
|
||||||
|
|
||||||
|
logger.info("--> verifying get with no routing, should not find anything");
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
assertThat(client.prepareGet("test", "type1", "1").execute().actionGet().exists(), equalTo(false));
|
||||||
|
}
|
||||||
|
logger.info("--> verifying get with routing, should find");
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
assertThat(client.prepareGet("test", "type1", "1").setRouting("0").execute().actionGet().exists(), equalTo(true));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue