slim down the mapping serialization to xcontent (json), don't write default values

This commit is contained in:
kimchy 2010-11-07 12:33:44 +02:00
parent e44604b441
commit 7340d6973d
24 changed files with 288 additions and 58 deletions

View File

@ -30,7 +30,7 @@ import org.elasticsearch.common.util.concurrent.ThreadSafe;
import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.field.data.FieldDataType;
/** /**
* @author kimchy (Shay Banon) * @author kimchy (shay.banon)
*/ */
@ThreadSafe @ThreadSafe
public interface FieldMapper<T> { public interface FieldMapper<T> {

View File

@ -396,18 +396,22 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, XContent
protected void doXContentBody(XContentBuilder builder) throws IOException { protected void doXContentBody(XContentBuilder builder) throws IOException {
builder.field("type", contentType()); builder.field("type", contentType());
builder.field("index_name", names.indexNameClean()); if (!names.name().equals(names.indexNameClean())) {
builder.field("index", index.name().toLowerCase()); builder.field("index_name", names.indexNameClean());
builder.field("store", store.name().toLowerCase());
builder.field("term_vector", termVector.name().toLowerCase());
builder.field("boost", boost);
builder.field("omit_norms", omitNorms);
builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions);
if (indexAnalyzer != null && !indexAnalyzer.name().startsWith("_")) {
builder.field("index_analyzer", indexAnalyzer.name());
} }
if (searchAnalyzer != null && !searchAnalyzer.name().startsWith("_")) { if (boost != 1.0f) {
builder.field("search_analyzer", searchAnalyzer.name()); builder.field("boost", boost);
}
if (indexAnalyzer != null && searchAnalyzer != null && indexAnalyzer.name().equals(searchAnalyzer.name()) && !indexAnalyzer.name().startsWith("_")) {
// same analyzers, output it once
builder.field("analyzer", indexAnalyzer.name());
} else {
if (indexAnalyzer != null && !indexAnalyzer.name().startsWith("_")) {
builder.field("index_analyzer", indexAnalyzer.name());
}
if (searchAnalyzer != null && !searchAnalyzer.name().startsWith("_")) {
builder.field("search_analyzer", searchAnalyzer.name());
}
} }
} }

View File

@ -154,15 +154,30 @@ public class AllFieldMapper extends AbstractFieldMapper<Void> implements org.ela
} }
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(CONTENT_TYPE); // if all are defaults, no need to write it at all
builder.field("enabled", enabled); if (enabled == Defaults.ENABLED && store == Defaults.STORE && termVector == Defaults.TERM_VECTOR && indexAnalyzer == null && searchAnalyzer == null) {
builder.field("store", store.name().toLowerCase()); return;
builder.field("term_vector", termVector.name().toLowerCase());
if (indexAnalyzer != null && !indexAnalyzer.name().startsWith("_")) {
builder.field("index_analyzer", indexAnalyzer.name());
} }
if (searchAnalyzer != null && !searchAnalyzer.name().startsWith("_")) { builder.startObject(CONTENT_TYPE);
builder.field("search_analyzer", searchAnalyzer.name()); if (enabled != Defaults.ENABLED) {
builder.field("enabled", enabled);
}
if (store != Defaults.STORE) {
builder.field("store", store.name().toLowerCase());
}
if (termVector != Defaults.TERM_VECTOR) {
builder.field("term_vector", termVector.name().toLowerCase());
}
if (indexAnalyzer != null && searchAnalyzer != null && indexAnalyzer.name().equals(searchAnalyzer.name()) && !indexAnalyzer.name().startsWith("_")) {
// same analyzers, output it once
builder.field("analyzer", indexAnalyzer.name());
} else {
if (indexAnalyzer != null && !indexAnalyzer.name().startsWith("_")) {
builder.field("index_analyzer", indexAnalyzer.name());
}
if (searchAnalyzer != null && !searchAnalyzer.name().startsWith("_")) {
builder.field("search_analyzer", searchAnalyzer.name());
}
} }
builder.endObject(); builder.endObject();
} }

View File

@ -102,7 +102,9 @@ public class BinaryFieldMapper extends AbstractFieldMapper<byte[]> {
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(names.name()); builder.startObject(names.name());
builder.field("type", contentType()); builder.field("type", contentType());
builder.field("index_name", names.indexNameClean()); if (!names.name().equals(names.indexNameClean())) {
builder.field("index_name", names.indexNameClean());
}
builder.endObject(); builder.endObject();
} }
} }

View File

@ -167,6 +167,21 @@ public class BooleanFieldMapper extends AbstractFieldMapper<Boolean> {
@Override protected void doXContentBody(XContentBuilder builder) throws IOException { @Override protected void doXContentBody(XContentBuilder builder) throws IOException {
super.doXContentBody(builder); super.doXContentBody(builder);
if (index != Defaults.INDEX) {
builder.field("index", index.name().toLowerCase());
}
if (store != Defaults.STORE) {
builder.field("store", store.name().toLowerCase());
}
if (termVector != Defaults.TERM_VECTOR) {
builder.field("term_vector", termVector.name().toLowerCase());
}
if (omitNorms != Defaults.OMIT_NORMS) {
builder.field("omit_norms", omitNorms);
}
if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) {
builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions);
}
if (nullValue != null) { if (nullValue != null) {
builder.field("null_value", nullValue); builder.field("null_value", nullValue);
} }

View File

@ -176,8 +176,14 @@ public class BoostFieldMapper extends NumberFieldMapper<Float> implements org.el
} }
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
// all are defaults, don't write it at all
if (name().equals(Defaults.NAME) && nullValue == null) {
return;
}
builder.startObject(contentType()); builder.startObject(contentType());
builder.field("name", name()); if (!name().equals(Defaults.NAME)) {
builder.field("name", name());
}
if (nullValue != null) { if (nullValue != null) {
builder.field("null_value", nullValue); builder.field("null_value", nullValue);
} }

View File

@ -222,6 +222,24 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
@Override protected void doXContentBody(XContentBuilder builder) throws IOException { @Override protected void doXContentBody(XContentBuilder builder) throws IOException {
super.doXContentBody(builder); super.doXContentBody(builder);
if (index != Defaults.INDEX) {
builder.field("index", index.name().toLowerCase());
}
if (store != Defaults.STORE) {
builder.field("store", store.name().toLowerCase());
}
if (termVector != Defaults.TERM_VECTOR) {
builder.field("term_vector", termVector.name().toLowerCase());
}
if (omitNorms != Defaults.OMIT_NORMS) {
builder.field("omit_norms", omitNorms);
}
if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) {
builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions);
}
if (precisionStep != Defaults.PRECISION_STEP) {
builder.field("precision_step", precisionStep);
}
builder.field("format", dateTimeFormatter.format()); builder.field("format", dateTimeFormatter.format());
if (nullValue != null) { if (nullValue != null) {
builder.field("null_value", nullValue); builder.field("null_value", nullValue);

View File

@ -205,6 +205,24 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
@Override protected void doXContentBody(XContentBuilder builder) throws IOException { @Override protected void doXContentBody(XContentBuilder builder) throws IOException {
super.doXContentBody(builder); super.doXContentBody(builder);
if (index != Defaults.INDEX) {
builder.field("index", index.name().toLowerCase());
}
if (store != Defaults.STORE) {
builder.field("store", store.name().toLowerCase());
}
if (termVector != Defaults.TERM_VECTOR) {
builder.field("term_vector", termVector.name().toLowerCase());
}
if (omitNorms != Defaults.OMIT_NORMS) {
builder.field("omit_norms", omitNorms);
}
if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) {
builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions);
}
if (precisionStep != Defaults.PRECISION_STEP) {
builder.field("precision_step", precisionStep);
}
if (nullValue != null) { if (nullValue != null) {
builder.field("null_value", nullValue); builder.field("null_value", nullValue);
} }

View File

@ -205,6 +205,24 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
@Override protected void doXContentBody(XContentBuilder builder) throws IOException { @Override protected void doXContentBody(XContentBuilder builder) throws IOException {
super.doXContentBody(builder); super.doXContentBody(builder);
if (index != Defaults.INDEX) {
builder.field("index", index.name().toLowerCase());
}
if (store != Defaults.STORE) {
builder.field("store", store.name().toLowerCase());
}
if (termVector != Defaults.TERM_VECTOR) {
builder.field("term_vector", termVector.name().toLowerCase());
}
if (omitNorms != Defaults.OMIT_NORMS) {
builder.field("omit_norms", omitNorms);
}
if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) {
builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions);
}
if (precisionStep != Defaults.PRECISION_STEP) {
builder.field("precision_step", precisionStep);
}
if (nullValue != null) { if (nullValue != null) {
builder.field("null_value", nullValue); builder.field("null_value", nullValue);
} }

View File

@ -121,8 +121,14 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements org.el
} }
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
// if all are defaults, no sense to write it at all
if (store == Defaults.STORE) {
return;
}
builder.startObject(CONTENT_TYPE); builder.startObject(CONTENT_TYPE);
builder.field("store", store.name().toLowerCase()); if (store != Defaults.STORE) {
builder.field("store", store.name().toLowerCase());
}
builder.endObject(); builder.endObject();
} }

View File

@ -128,9 +128,17 @@ public class IndexFieldMapper extends AbstractFieldMapper<String> implements org
} }
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
// if all defaults, no need to write it at all
if (store == Defaults.STORE && enabled == Defaults.ENABLED) {
return;
}
builder.startObject(CONTENT_TYPE); builder.startObject(CONTENT_TYPE);
builder.field("store", store.name().toLowerCase()); if (store != Defaults.STORE) {
builder.field("enabled", enabled); builder.field("store", store.name().toLowerCase());
}
if (enabled != Defaults.ENABLED) {
builder.field("enabled", enabled);
}
builder.endObject(); builder.endObject();
} }

View File

@ -204,6 +204,24 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
@Override protected void doXContentBody(XContentBuilder builder) throws IOException { @Override protected void doXContentBody(XContentBuilder builder) throws IOException {
super.doXContentBody(builder); super.doXContentBody(builder);
if (index != Defaults.INDEX) {
builder.field("index", index.name().toLowerCase());
}
if (store != Defaults.STORE) {
builder.field("store", store.name().toLowerCase());
}
if (termVector != Defaults.TERM_VECTOR) {
builder.field("term_vector", termVector.name().toLowerCase());
}
if (omitNorms != Defaults.OMIT_NORMS) {
builder.field("omit_norms", omitNorms);
}
if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) {
builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions);
}
if (precisionStep != Defaults.PRECISION_STEP) {
builder.field("precision_step", precisionStep);
}
if (nullValue != null) { if (nullValue != null) {
builder.field("null_value", nullValue); builder.field("null_value", nullValue);
} }

View File

@ -237,6 +237,24 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
@Override protected void doXContentBody(XContentBuilder builder) throws IOException { @Override protected void doXContentBody(XContentBuilder builder) throws IOException {
super.doXContentBody(builder); super.doXContentBody(builder);
if (index != Defaults.INDEX) {
builder.field("index", index.name().toLowerCase());
}
if (store != Defaults.STORE) {
builder.field("store", store.name().toLowerCase());
}
if (termVector != Defaults.TERM_VECTOR) {
builder.field("term_vector", termVector.name().toLowerCase());
}
if (omitNorms != Defaults.OMIT_NORMS) {
builder.field("omit_norms", omitNorms);
}
if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) {
builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions);
}
if (precisionStep != Defaults.PRECISION_STEP) {
builder.field("precision_step", precisionStep);
}
if (nullValue != null) { if (nullValue != null) {
builder.field("null_value", nullValue); builder.field("null_value", nullValue);
} }

View File

@ -204,6 +204,24 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
@Override protected void doXContentBody(XContentBuilder builder) throws IOException { @Override protected void doXContentBody(XContentBuilder builder) throws IOException {
super.doXContentBody(builder); super.doXContentBody(builder);
if (index != Defaults.INDEX) {
builder.field("index", index.name().toLowerCase());
}
if (store != Defaults.STORE) {
builder.field("store", store.name().toLowerCase());
}
if (termVector != Defaults.TERM_VECTOR) {
builder.field("term_vector", termVector.name().toLowerCase());
}
if (omitNorms != Defaults.OMIT_NORMS) {
builder.field("omit_norms", omitNorms);
}
if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) {
builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions);
}
if (precisionStep != Defaults.PRECISION_STEP) {
builder.field("precision_step", precisionStep);
}
if (nullValue != null) { if (nullValue != null) {
builder.field("null_value", nullValue); builder.field("null_value", nullValue);
} }

View File

@ -266,7 +266,9 @@ public class MultiFieldMapper implements XContentMapper, IncludeInAllMapper {
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(name); builder.startObject(name);
builder.field("type", CONTENT_TYPE); builder.field("type", CONTENT_TYPE);
builder.field("path", pathType.name().toLowerCase()); if (pathType != Defaults.PATH_TYPE) {
builder.field("path", pathType.name().toLowerCase());
}
builder.startObject("fields"); builder.startObject("fields");
if (defaultMapper != null) { if (defaultMapper != null) {

View File

@ -28,7 +28,6 @@ import org.apache.lucene.search.Query;
import org.apache.lucene.util.NumericUtils; import org.apache.lucene.util.NumericUtils;
import org.elasticsearch.common.thread.ThreadLocals; import org.elasticsearch.common.thread.ThreadLocals;
import org.elasticsearch.common.trove.TIntObjectHashMap; import org.elasticsearch.common.trove.TIntObjectHashMap;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.field.data.FieldDataType;
import org.elasticsearch.index.mapper.MergeMappingException; import org.elasticsearch.index.mapper.MergeMappingException;
@ -166,16 +165,11 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
} }
} }
@Override protected void doXContentBody(XContentBuilder builder) throws IOException {
super.doXContentBody(builder);
builder.field("precision_step", precisionStep);
}
@Override public abstract FieldDataType fieldDataType(); @Override public abstract FieldDataType fieldDataType();
/** /**
* Removes a cached numeric token stream. The stream will be returned to the cahed once it is used * Removes a cached numeric token stream. The stream will be returned to the cached once it is used
* sicne it implements the end method. * since it implements the end method.
*/ */
protected CachedNumericTokenStream popCachedStream(int precisionStep) { protected CachedNumericTokenStream popCachedStream(int precisionStep) {
Deque<CachedNumericTokenStream> deque = cachedStreams.get().get().get(precisionStep); Deque<CachedNumericTokenStream> deque = cachedStreams.get().get().get(precisionStep);

View File

@ -551,10 +551,18 @@ public class ObjectMapper implements XContentMapper, IncludeInAllMapper {
public void toXContent(XContentBuilder builder, Params params, XContentMapper... additionalMappers) throws IOException { public void toXContent(XContentBuilder builder, Params params, XContentMapper... additionalMappers) throws IOException {
builder.startObject(name); builder.startObject(name);
builder.field("type", CONTENT_TYPE); if (mappers.isEmpty()) { // only write the object content type if there are no properties, otherwise, it is automatically detected
builder.field("dynamic", dynamic); builder.field("type", CONTENT_TYPE);
builder.field("enabled", enabled); }
builder.field("path", pathType.name().toLowerCase()); if (dynamic != Defaults.DYNAMIC) {
builder.field("dynamic", dynamic);
}
if (enabled != Defaults.ENABLED) {
builder.field("enabled", enabled);
}
if (pathType != Defaults.PATH_TYPE) {
builder.field("path", pathType.name().toLowerCase());
}
if (includeInAll != null) { if (includeInAll != null) {
builder.field("include_in_all", includeInAll); builder.field("include_in_all", includeInAll);
} }

View File

@ -93,14 +93,17 @@ public class RootObjectMapper extends ObjectMapper {
@Override protected ObjectMapper createMapper(String name, boolean enabled, boolean dynamic, ContentPath.Type pathType, Map<String, XContentMapper> mappers) { @Override protected ObjectMapper createMapper(String name, boolean enabled, boolean dynamic, ContentPath.Type pathType, Map<String, XContentMapper> mappers) {
FormatDateTimeFormatter[] dates = null;
if (dateTimeFormatters == null) { if (dateTimeFormatters == null) {
dateTimeFormatters = newArrayList(); dates = new FormatDateTimeFormatter[0];
} else if (dateTimeFormatters.isEmpty()) { } else if (dateTimeFormatters.isEmpty()) {
// add the default one // add the default one
dateTimeFormatters.addAll(newArrayList(Defaults.DATE_TIME_FORMATTERS)); dates = Defaults.DATE_TIME_FORMATTERS;
} else {
dates = dateTimeFormatters.toArray(new FormatDateTimeFormatter[dateTimeFormatters.size()]);
} }
return new RootObjectMapper(name, enabled, dynamic, pathType, mappers, return new RootObjectMapper(name, enabled, dynamic, pathType, mappers,
dateTimeFormatters.toArray(new FormatDateTimeFormatter[dateTimeFormatters.size()]), dates,
dynamicTemplates.toArray(new DynamicTemplate[dynamicTemplates.size()])); dynamicTemplates.toArray(new DynamicTemplate[dynamicTemplates.size()]));
} }
} }
@ -206,12 +209,14 @@ public class RootObjectMapper extends ObjectMapper {
} }
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException {
if (dateTimeFormatters.length > 0) { if (dateTimeFormatters != Defaults.DATE_TIME_FORMATTERS) {
builder.startArray("date_formats"); if (dateTimeFormatters.length > 0) {
for (FormatDateTimeFormatter dateTimeFormatter : dateTimeFormatters) { builder.startArray("date_formats");
builder.value(dateTimeFormatter.format()); for (FormatDateTimeFormatter dateTimeFormatter : dateTimeFormatters) {
builder.value(dateTimeFormatter.format());
}
builder.endArray();
} }
builder.endArray();
} }
if (dynamicTemplates != null && dynamicTemplates.length > 0) { if (dynamicTemplates != null && dynamicTemplates.length > 0) {

View File

@ -204,6 +204,24 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
@Override protected void doXContentBody(XContentBuilder builder) throws IOException { @Override protected void doXContentBody(XContentBuilder builder) throws IOException {
super.doXContentBody(builder); super.doXContentBody(builder);
if (index != Defaults.INDEX) {
builder.field("index", index.name().toLowerCase());
}
if (store != Defaults.STORE) {
builder.field("store", store.name().toLowerCase());
}
if (termVector != Defaults.TERM_VECTOR) {
builder.field("term_vector", termVector.name().toLowerCase());
}
if (omitNorms != Defaults.OMIT_NORMS) {
builder.field("omit_norms", omitNorms);
}
if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) {
builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions);
}
if (precisionStep != Defaults.PRECISION_STEP) {
builder.field("precision_step", precisionStep);
}
if (nullValue != null) { if (nullValue != null) {
builder.field("null_value", nullValue); builder.field("null_value", nullValue);
} }

View File

@ -168,9 +168,14 @@ public class SourceFieldMapper extends AbstractFieldMapper<byte[]> implements or
} }
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
// all are defaults, no need to write it at all
if (enabled == Defaults.ENABLED && compress == null) {
return;
}
builder.startObject(contentType()); builder.startObject(contentType());
builder.field("name", name()); if (enabled != Defaults.ENABLED) {
builder.field("enabled", enabled); builder.field("enabled", enabled);
}
if (compress != null) { if (compress != null) {
builder.field("compress", compress); builder.field("compress", compress);
} }

View File

@ -166,6 +166,21 @@ public class StringFieldMapper extends AbstractFieldMapper<String> implements In
@Override protected void doXContentBody(XContentBuilder builder) throws IOException { @Override protected void doXContentBody(XContentBuilder builder) throws IOException {
super.doXContentBody(builder); super.doXContentBody(builder);
if (index != Defaults.INDEX) {
builder.field("index", index.name().toLowerCase());
}
if (store != Defaults.STORE) {
builder.field("store", store.name().toLowerCase());
}
if (termVector != Defaults.TERM_VECTOR) {
builder.field("term_vector", termVector.name().toLowerCase());
}
if (omitNorms != Defaults.OMIT_NORMS) {
builder.field("omit_norms", omitNorms);
}
if (omitTermFreqAndPositions != Defaults.OMIT_TERM_FREQ_AND_POSITIONS) {
builder.field("omit_term_freq_and_positions", omitTermFreqAndPositions);
}
if (nullValue != null) { if (nullValue != null) {
builder.field("null_value", nullValue); builder.field("null_value", nullValue);
} }

View File

@ -110,8 +110,14 @@ public class TypeFieldMapper extends AbstractFieldMapper<String> implements org.
} }
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
// if all are defaults, no sense to write it at all
if (store == Defaults.STORE) {
return;
}
builder.startObject(CONTENT_TYPE); builder.startObject(CONTENT_TYPE);
builder.field("store", store.name().toLowerCase()); if (store != Defaults.STORE) {
builder.field("store", store.name().toLowerCase());
}
builder.endObject(); builder.endObject();
} }

View File

@ -66,19 +66,22 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
public static class Defaults { public static class Defaults {
public static final ContentPath.Type PATH_TYPE = ContentPath.Type.FULL; public static final ContentPath.Type PATH_TYPE = ContentPath.Type.FULL;
public static final Field.Store STORE = Field.Store.NO; public static final Field.Store STORE = Field.Store.NO;
public static final boolean ENABLE_LATLON = false;
public static final boolean ENABLE_GEOHASH = false;
public static final int PRECISION = GeoHashUtils.PRECISION;
} }
public static class Builder extends XContentMapper.Builder<Builder, GeoPointFieldMapper> { public static class Builder extends XContentMapper.Builder<Builder, GeoPointFieldMapper> {
private ContentPath.Type pathType = Defaults.PATH_TYPE; private ContentPath.Type pathType = Defaults.PATH_TYPE;
private boolean enableGeoHash = false; private boolean enableGeoHash = Defaults.ENABLE_GEOHASH;
private boolean enableLatLon = false; private boolean enableLatLon = Defaults.ENABLE_LATLON;
private Integer precisionStep; private Integer precisionStep;
private int precision = GeoHashUtils.PRECISION; private int precision = Defaults.PRECISION;
private Field.Store store = Defaults.STORE; private Field.Store store = Defaults.STORE;
@ -354,11 +357,21 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(name); builder.startObject(name);
builder.field("type", CONTENT_TYPE); builder.field("type", CONTENT_TYPE);
builder.field("path", pathType.name().toLowerCase()); if (pathType != Defaults.PATH_TYPE) {
builder.field("lat_lon", enableLatLon); builder.field("path", pathType.name().toLowerCase());
builder.field("geohash", enableGeoHash); }
builder.field("store", geoStringMapper.store().name().toLowerCase()); if (enableLatLon != Defaults.ENABLE_LATLON) {
builder.field("geohash_precision", precision); builder.field("lat_lon", enableLatLon);
}
if (enableGeoHash != Defaults.ENABLE_GEOHASH) {
builder.field("geohash", enableGeoHash);
}
if (geoStringMapper.store() != Defaults.STORE) {
builder.field("store", geoStringMapper.store().name().toLowerCase());
}
if (precision != Defaults.PRECISION) {
builder.field("geohash_precision", precision);
}
if (precisionStep != null) { if (precisionStep != null) {
builder.field("precision_step", precisionStep); builder.field("precision_step", precisionStep);
} }

View File

@ -103,7 +103,7 @@ public class UpdateNumberOfReplicasTests extends AbstractNodesTests {
Thread.sleep(200); Thread.sleep(200);
logger.info("Running Cluster Health"); logger.info("Running Cluster Health");
clusterHealth = client1.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(); clusterHealth = client1.admin().cluster().prepareHealth().setWaitForYellowStatus().setWaitForActiveShards(10).execute().actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.status()); logger.info("Done Cluster Health, status " + clusterHealth.status());
assertThat(clusterHealth.timedOut(), equalTo(false)); assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW)); assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW));