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

Throw a parsing exception when boost is set in span_or query (#28390) #34112

Merged
merged 48 commits into from
Nov 26, 2018
Merged
Changes from 2 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
6c12c4a
Throw a parsing exception when boost is set in span_or query (#28390)
cbismuth Sep 27, 2018
265acde
Throw a parsing exception when boost is parsed in span_or query (#28390)
cbismuth Sep 27, 2018
268b78e
Check boost field only in SpanOrQueryBuilder#fromXContent API (#28390)
cbismuth Oct 4, 2018
6effd0a
Throw a parsing exception only when boost differs from default (#28390)
cbismuth Oct 4, 2018
6349cb3
Set per query builder "boost" and "query name" support (#28390)
cbismuth Oct 5, 2018
e8b61bd
Merge branch 'master' into 28390_disallow_setting_boosts_on_inner_spa…
cbismuth Oct 5, 2018
04f66ce
Merge branch 'master' into 28390_disallow_setting_boosts_on_inner_spa…
cbismuth Oct 10, 2018
8029eb2
Allow non-default boost value in outer "span_or" query(#28390)
cbismuth Oct 10, 2018
0f95a83
Revert "Set per query builder "boost" and "query name" support (#28390)"
cbismuth Oct 10, 2018
e94a942
Allow disabling boost and query name in test query builders (#28390)
cbismuth Oct 10, 2018
7c348bf
Restore previous boost and query name API (#28390)
cbismuth Oct 10, 2018
a20d761
Disallow setting boost in "span_containing" queries (#28390)
cbismuth Oct 10, 2018
e39bf1d
Disallow setting boost in "span_within" queries (#28390)
cbismuth Oct 10, 2018
bee3ef6
Disallow setting boost in "span_near" queries (#28390)
cbismuth Oct 10, 2018
c48777c
Fix "span_or" query builder exception message format (#28390)
cbismuth Oct 10, 2018
9426ffe
Disallow setting boost in "span_not" queries (#28390)
cbismuth Oct 10, 2018
af54fc8
Restore query name generation in test query builders (#28390)
cbismuth Oct 10, 2018
87da533
Ensure boost can be set in outer "span_containing" queries (#28390)
cbismuth Oct 10, 2018
95ff5ed
Ensure boost can be set in outer "span_near" queries (#28390)
cbismuth Oct 10, 2018
7d25d14
Ensure boost can be set in outer "span_not" queries (#28390)
cbismuth Oct 10, 2018
1f08196
Ensure boost can be set in outer "span_or" queries (#28390)
cbismuth Oct 10, 2018
daea8b1
Ensure boost can be set in outer "span_within" queries (#28390)
cbismuth Oct 10, 2018
70cffbe
Disallow setting boost in "span_gap" queries (#28390)
cbismuth Oct 10, 2018
9e433b3
Extract method to check no boost value has been set (#28390)
cbismuth Oct 10, 2018
006b37d
Reuse query name in exception message (#28390)
cbismuth Oct 10, 2018
8f8e035
Merge branch 'master' into 28390_disallow_setting_boosts_on_inner_spa…
cbismuth Oct 25, 2018
e8ec5c1
Merge branch 'master' into 28390_disallow_setting_boosts_on_inner_spa…
cbismuth Nov 6, 2018
a5dd5b8
Merge branch 'master' into 28390_disallow_setting_boosts_on_inner_spa…
cbismuth Nov 14, 2018
49ce791
Merge branch 'master' into 28390_disallow_setting_boosts_on_inner_spa…
cbismuth Nov 16, 2018
0ac11ec
Merge branch 'master' into 28390_disallow_setting_boosts_on_inner_spa…
cbismuth Nov 16, 2018
a88866e
Merge branch 'master' into 28390_disallow_setting_boosts_on_inner_spa…
cbismuth Nov 18, 2018
9c751b1
Move check method to base SpanQueryBuilder class (#28390)
cbismuth Nov 19, 2018
8a75747
Improve "checkNoBoost" exception message (#28390)
cbismuth Nov 19, 2018
8e9c70d
Split `supportsBoost` and `supportsQueryName` test API (#28390)
cbismuth Nov 19, 2018
f2861cd
Remove unnecessary `supportsQueryName` parameter in test API (#28390)
cbismuth Nov 19, 2018
df03f38
Merge branch 'master' into 28390_disallow_setting_boosts_on_inner_spa…
cbismuth Nov 19, 2018
11f6060
Remove boost support from span query test API (#28390)
cbismuth Nov 20, 2018
043020b
Remove underscore characters in test names (#28390)
cbismuth Nov 20, 2018
c96aaa9
Remove boost support from `span_first` query (#28390)
cbismuth Nov 20, 2018
3b667bf
Merge branch 'master' into 28390_disallow_setting_boosts_on_inner_spa…
cbismuth Nov 20, 2018
259c446
Add migration to 7.x breaking change disclaimer (#28390)
cbismuth Nov 20, 2018
e486466
Merge branch 'master' into 28390_disallow_setting_boosts_on_inner_spa…
cbismuth Nov 21, 2018
78e8c21
Update documentation (#28390)
cbismuth Nov 21, 2018
16127d9
Merge branch 'master' into 28390_disallow_setting_boosts_on_inner_spa…
cbismuth Nov 22, 2018
1fb94ee
Revert "Update documentation (#28390)"
cbismuth Nov 22, 2018
94b5bcb
Fix line length to 80 characters (#28390)
cbismuth Nov 22, 2018
dc1e913
Merge branch 'master' into 28390_disallow_setting_boosts_on_inner_spa…
cbismuth Nov 22, 2018
309e00b
Merge branch 'master' into 28390_disallow_setting_boosts_on_inner_spa…
cbismuth Nov 23, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentLocation;
import org.elasticsearch.common.xcontent.XContentParser;

import java.io.IOException;
Expand All @@ -49,7 +50,7 @@ public SpanOrQueryBuilder(SpanQueryBuilder initialClause) {
if (initialClause == null) {
throw new IllegalArgumentException("[" + NAME + "] must include at least one clause");
}
clauses.add(initialClause);
addClause(initialClause);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not necessary. The only place where we should do the check is inside fromXContent method for all span query builders : SpanOrQueryBuilder, SpanTermQueryBuilder etc.

}

/**
Expand All @@ -58,7 +59,7 @@ public SpanOrQueryBuilder(SpanQueryBuilder initialClause) {
public SpanOrQueryBuilder(StreamInput in) throws IOException {
super(in);
for (QueryBuilder clause: readQueries(in)) {
clauses.add((SpanQueryBuilder) clause);
addClause((SpanQueryBuilder) clause);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not necessary. This comes from another node that presumably already failed a span query if it contains boost.
The only place where we should do the check is inside fromXContent method for all span query builders : SpanOrQueryBuilder, SpanTermQueryBuilder etc

}
}

Expand All @@ -74,10 +75,23 @@ public SpanOrQueryBuilder addClause(SpanQueryBuilder clause) {
if (clause == null) {
throw new IllegalArgumentException("[" + NAME + "] inner clause cannot be null");
}
checkBoostValue(clause);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment here: I think this is not necessary. The only place where we should do the check is inside fromXContent method for all span query builders : SpanOrQueryBuilder, SpanTermQueryBuilder etc.

clauses.add(clause);
return this;
}

private static void checkBoostValue(SpanQueryBuilder clause) {
if (clause.boost() != AbstractQueryBuilder.DEFAULT_BOOST) {
throw new IllegalArgumentException("spanOr [clauses] can't have boost value");
}
}

private static void checkBoostValue(XContentLocation location, SpanQueryBuilder clause) {
if (clause.boost() != AbstractQueryBuilder.DEFAULT_BOOST) {
throw new ParsingException(location, "spanOr [clauses] can't have boost value");
}
}

/**
* @return the {@link SpanQueryBuilder} clauses that were set for this query
*/
Expand Down Expand Up @@ -115,14 +129,16 @@ public static SpanOrQueryBuilder fromXContent(XContentParser parser) throws IOEx
if (query instanceof SpanQueryBuilder == false) {
throw new ParsingException(parser.getTokenLocation(), "spanOr [clauses] must be of type span query");
}
clauses.add((SpanQueryBuilder) query);
final SpanQueryBuilder clause = (SpanQueryBuilder) query;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these 3 lines are not necessary, as each inner SpanQueryBuilder within their fromXContent should check for boost and fail if boost provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compound span_or queries can contain span_term inner queries and setting boost in span_term queries is allowed, that's why I've added this check here, do you agree with it? See this test.

checkBoostValue(parser.getTokenLocation(), clause);
clauses.add(clause);
}
} else {
throw new ParsingException(parser.getTokenLocation(), "[span_or] query does not support [" + currentFieldName + "]");
}
} else {
if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
boost = parser.floatValue();
throw new ParsingException(parser.getTokenLocation(), "spanOr [clauses] can't have boost value");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is great and I think the only necessary change in SpanOrQueryBuilder. All other SpanQueryBuilders should have similar line in their fromXContent methods.

} else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
queryName = parser.text();
} else {
Expand Down