-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
BoolQueryBuilder uses ObjectParser #52880
Merged
romseygeek
merged 5 commits into
elastic:master
from
romseygeek:refactor/boolqueryparser
Mar 4, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
278daaa
BoolQueryBuilder uses ObjectParser
romseygeek ec59f97
msm can be string or number
romseygeek f0f9b15
assert on wrapped exception as well
romseygeek 02dbd64
Merge remote-tracking branch 'origin/master' into refactor/boolqueryp…
romseygeek ba4f065
Merge branch 'master' into refactor/boolqueryparser
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,9 @@ | |
import org.apache.lucene.search.MatchAllDocsQuery; | ||
import org.apache.lucene.search.MatchNoDocsQuery; | ||
import org.apache.lucene.search.Query; | ||
import org.elasticsearch.common.ParsingException; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentFactory; | ||
import org.elasticsearch.common.xcontent.XContentParseException; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.test.AbstractQueryTestCase; | ||
|
@@ -41,6 +41,7 @@ | |
|
||
import static org.elasticsearch.index.query.QueryBuilders.boolQuery; | ||
import static org.elasticsearch.index.query.QueryBuilders.termQuery; | ||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
|
||
|
@@ -277,14 +278,23 @@ public void testFromJson() throws IOException { | |
assertEquals(query, "kimchy", ((TermQueryBuilder)queryBuilder.must().get(0)).value()); | ||
} | ||
|
||
public void testMinimumShouldMatchNumber() throws IOException { | ||
String query = "{\"bool\" : {\"must\" : { \"term\" : { \"field\" : \"value\" } }, \"minimum_should_match\" : 1 } }"; | ||
BoolQueryBuilder builder = (BoolQueryBuilder) parseQuery(query); | ||
assertEquals("1", builder.minimumShouldMatch()); | ||
} | ||
|
||
/** | ||
* test that unknown query names in the clauses throw an error | ||
*/ | ||
public void testUnknownQueryName() throws IOException { | ||
String query = "{\"bool\" : {\"must\" : { \"unknown_query\" : { } } } }"; | ||
|
||
ParsingException ex = expectThrows(ParsingException.class, () -> parseQuery(query)); | ||
assertEquals("unknown query [unknown_query]", ex.getMessage()); | ||
XContentParseException ex = expectThrows(XContentParseException.class, () -> parseQuery(query)); | ||
assertEquals("[1:41] [bool] failed to parse field [must]", ex.getMessage()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth asserting on the "inner" exception too. Or something. Because this message isn't nearly a nice as the other one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ++ I pushed f0f9b15 |
||
Throwable e = ex.getCause(); | ||
assertThat(e.getMessage(), containsString("unknown query [unknown_query]")); | ||
|
||
} | ||
|
||
public void testRewrite() throws IOException { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll do this in a followup to get more eyes on it.