Skip to content

Commit

Permalink
Allow the _boost field to be indexed and stored.
Browse files Browse the repository at this point in the history
Closes #3752
  • Loading branch information
brusic authored and martijnvg committed Sep 20, 2013
1 parent a1185a9 commit ab05f92
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ public SizeFieldMapper SizeFieldMapper() {
return rootMapper(SizeFieldMapper.class);
}

public BoostFieldMapper boostFieldMapper() {
return rootMapper(BoostFieldMapper.class);
}

public Analyzer indexAnalyzer() {
return this.indexAnalyzer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ protected String contentType() {
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
// all are defaults, don't write it at all
if (name().equals(Defaults.NAME) && nullValue == null) {
if (name().equals(Defaults.NAME) && nullValue == null &&
fieldType.indexed() == Defaults.FIELD_TYPE.indexed() &&
fieldType.stored() == Defaults.FIELD_TYPE.stored()) {
return builder;
}
builder.startObject(contentType());
Expand All @@ -286,6 +288,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}
if (nullValue != null) {
builder.field("null_value", nullValue);
}
if (fieldType.indexed() != Defaults.FIELD_TYPE.indexed()) {
builder.field("index", fieldType.indexed());
}
if (fieldType.stored() != Defaults.FIELD_TYPE.stored()) {
builder.field("store", fieldType.stored());
}
builder.endObject();
return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.internal.BoostFieldMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.junit.Test;

Expand Down Expand Up @@ -71,4 +72,24 @@ public void testCustomName() throws Exception {
.endObject().bytes());
assertThat(doc.rootDoc().getField("field").boost(), equalTo(2.0f));
}

@Test
public void testDefaultValues() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
assertThat(docMapper.boostFieldMapper().fieldType().stored(), equalTo(BoostFieldMapper.Defaults.FIELD_TYPE.stored()));
assertThat(docMapper.boostFieldMapper().fieldType().indexed(), equalTo(BoostFieldMapper.Defaults.FIELD_TYPE.indexed()));
}

@Test
public void testSetValues() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_boost")
.field("store", "yes").field("index", "not_analyzed")
.endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
assertThat(docMapper.boostFieldMapper().fieldType().stored(), equalTo(true));
assertThat(docMapper.boostFieldMapper().fieldType().indexed(), equalTo(true));
}
}

0 comments on commit ab05f92

Please sign in to comment.