Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed boost name to path #4401

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions docs/reference/mapping/fields/boost-field.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
Boosting is the process of enhancing the relevancy of a document or
field. Field level mapping allows to define explicit boost level on a
specific field. The boost field mapping (applied on the
<<mapping-root-object-type,root object>>) allows
to define a boost field mapping where *its content will control the
boost level of the document*. For example, consider the following
mapping:
<<mapping-root-object-type,root object>>) allows to define
a boost field mapping where *its content will control the boost level
of the document*. `path` can be used to specify a field name where the
boost value will be taken from for each document. For example, consider
the following mapping:

[source,js]
--------------------------------------------------
{
"tweet" : {
"_boost" : {"name" : "my_boost", "null_value" : 1.0}
"_boost" : {"path" : "my_boost", "null_value" : 1.0}
}
}
--------------------------------------------------
Expand All @@ -30,3 +31,4 @@ following JSON document will be indexed with a boost value of `2.2`:
"message" : "This is a tweet!"
}
--------------------------------------------------

Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class BoostFieldMapper extends NumberFieldMapper<Float> implements Intern
public static final String NAME = "_boost";

public static class Defaults extends NumberFieldMapper.Defaults {
public static final String NAME = "_boost";
public static final String PATH = "_boost";
public static final Float NULL_VALUE = null;

public static final FieldType FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.FIELD_TYPE);
Expand Down Expand Up @@ -97,9 +97,9 @@ public BoostFieldMapper build(BuilderContext context) {
public static class TypeParser implements Mapper.TypeParser {
@Override
public Mapper.Builder parse(String fieldName, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
String name = node.get("name") == null ? BoostFieldMapper.Defaults.NAME : node.get("name").toString();
BoostFieldMapper.Builder builder = MapperBuilders.boost(name);
parseNumberField(builder, name, node, parserContext);
String path = node.get("path") == null ? BoostFieldMapper.Defaults.PATH : node.get("path").toString();
BoostFieldMapper.Builder builder = MapperBuilders.boost(path);
parseNumberField(builder, path, node, parserContext);
for (Map.Entry<String, Object> entry : node.entrySet()) {
String propName = Strings.toUnderscoreCase(entry.getKey());
Object propNode = entry.getValue();
Expand All @@ -114,7 +114,7 @@ public Mapper.Builder parse(String fieldName, Map<String, Object> node, ParserCo
private final Float nullValue;

public BoostFieldMapper() {
this(Defaults.NAME, Defaults.NAME);
this(Defaults.PATH, Defaults.PATH);
}

protected BoostFieldMapper(String name, String indexName) {
Expand Down Expand Up @@ -287,15 +287,15 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
boolean includeDefaults = params.paramAsBoolean("include_defaults", false);

// all are defaults, don't write it at all
if (!includeDefaults && name().equals(Defaults.NAME) && nullValue == null &&
if (!includeDefaults && name().equals(Defaults.PATH) && nullValue == null &&
fieldType.indexed() == Defaults.FIELD_TYPE.indexed() &&
fieldType.stored() == Defaults.FIELD_TYPE.stored() &&
customFieldDataSettings == null) {
return builder;
}
builder.startObject(contentType());
if (includeDefaults || !name().equals(Defaults.NAME)) {
builder.field("name", name());
if (includeDefaults || !name().equals(Defaults.PATH)) {
builder.field("path", name());
}
if (includeDefaults || nullValue != null) {
builder.field("null_value", nullValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.elasticsearch.test.ElasticsearchTestCase;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

/**
Expand All @@ -54,9 +53,9 @@ public void testDefaultMapping() throws Exception {
}

@Test
public void testCustomName() throws Exception {
public void testCustomPath() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_boost").field("name", "custom_boost").endObject()
.startObject("_boost").field("path", "custom_boost").endObject()
.endObject().endObject().string();

DocumentMapper mapper = MapperTestUtils.newParser().parse(mapping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
name:"_type"
},
_boost:{
name:"_boost",
path:"_boost",
null_value:2.0
},
properties:{
Expand Down