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

Remove the object format for indices_boost. #55078

Merged
merged 1 commit into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/reference/migration/migrate_8_0/search.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@ deprecated in 7.6, and are now removed in 8.x. The form
`cosineSimilarity(query, doc['field'])` is replaced by
`cosineSimilarity(query, 'field')`.

[float]
==== Object format for `indices_boost`
The `indices_boost` option in the search request used to accept the boosts
both as an object and as an array. The object format has been deprecated since
5.2 and is now removed in 8.0.
17 changes: 8 additions & 9 deletions docs/reference/search/request/index-boost.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ deprecated[5.2.0, This format is deprecated. Please use array format instead.]
--------------------------------------------------
GET /_search
{
"indices_boost" : {
"index1" : 1.4,
"index2" : 1.3
}
"indices_boost" : [
{ "index1" : 1.4 },
{ "index2" : 1.3 }
]
}
--------------------------------------------------
// TEST[setup:index_boost warning:Object format in indices_boost is deprecated, please use array format instead]
// TEST[setup:index_boost]

You can also specify it as an array to control the order of boosts.
Index aliases and wildcard expressions can also be used:

[source,console]
--------------------------------------------------
Expand All @@ -33,6 +33,5 @@ GET /_search
--------------------------------------------------
// TEST[continued]

This is important when you use aliases or wildcard expression.
If multiple matches are found, the first match will be used.
For example, if an index is included in both `alias1` and `index*`, boost value of `1.4` is applied.
If multiple matches are found, the first match will be used. For example, if an
index is included in both `alias1` and `index*`, boost value of `1.4` is applied.
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,7 @@ setup:
index: [test_1, test_2]

---
"Indices boost using object":
- skip:
features: "warnings"

- do:
warnings:
- 'Object format in indices_boost is deprecated, please use array format instead'
search:
rest_total_hits_as_int: true
index: _all
body:
indices_boost: {test_1: 2.0, test_2: 1.0}

- match: { hits.total: 2 }
- match: { hits.hits.0._index: test_1 }
- match: { hits.hits.1._index: test_2 }

- do:
warnings:
- 'Object format in indices_boost is deprecated, please use array format instead'
search:
rest_total_hits_as_int: true
index: _all
body:
indices_boost: {test_1: 1.0, test_2: 2.0}

- match: { hits.total: 2 }
- match: { hits.hits.0._index: test_2 }
- match: { hits.hits.1._index: test_1 }

---
"Indices boost using array":
"Basic indices boost":
- do:
search:
rest_total_hits_as_int: true
Expand All @@ -88,7 +57,7 @@ setup:
- match: { hits.hits.1._index: test_1 }

---
"Indices boost using array with alias":
"Indices boost with alias":
- do:
search:
rest_total_hits_as_int: true
Expand All @@ -112,7 +81,7 @@ setup:
- match: { hits.hits.1._index: test_1 }

---
"Indices boost using array with wildcard":
"Indices boost with wildcard":
- do:
search:
rest_total_hits_as_int: true
Expand All @@ -136,7 +105,7 @@ setup:
- match: { hits.hits.1._index: test_1 }

---
"Indices boost using array multiple match":
"Indices boost multiple match":
- do:
search:
rest_total_hits_as_int: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1076,19 +1076,6 @@ public void parseXContent(XContentParser parser, boolean checkTrailingTokens) th
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
scriptFields.add(new ScriptField(parser));
}
} else if (INDICES_BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
deprecationLogger.deprecated(
"Object format in indices_boost is deprecated, please use array format instead");
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
indexBoosts.add(new IndexBoost(currentFieldName, parser.floatValue()));
} else {
throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token +
" in [" + currentFieldName + "].", parser.getTokenLocation());
}
}
} else if (AGGREGATIONS_FIELD.match(currentFieldName, parser.getDeprecationHandler())
|| AGGS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
aggregations = AggregatorFactories.parseAggregators(parser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,17 +376,6 @@ public void testToXContent() throws IOException {
}

public void testParseIndicesBoost() throws IOException {
{
String restContent = " { \"indices_boost\": {\"foo\": 1.0, \"bar\": 2.0}}";
try (XContentParser parser = createParser(JsonXContent.jsonXContent, restContent)) {
SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(parser);
assertEquals(2, searchSourceBuilder.indexBoosts().size());
assertEquals(new SearchSourceBuilder.IndexBoost("foo", 1.0f), searchSourceBuilder.indexBoosts().get(0));
assertEquals(new SearchSourceBuilder.IndexBoost("bar", 2.0f), searchSourceBuilder.indexBoosts().get(1));
assertWarnings("Object format in indices_boost is deprecated, please use array format instead");
}
}

{
String restContent = "{" +
" \"indices_boost\" : [\n" +
Expand Down