-
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
Allow fields
to be set to *
#42301
Allow fields
to be set to *
#42301
Conversation
Allow for SimpleQueryString, QueryString and MultiMatchQuery to set the `fields` parameter to the wildcard `*`. If so, set the leniency to `true`, to achieve the same behaviour as from the `"default_field" : "*" setting. Closes: elastic#39577
Pinging @elastic/es-search |
if (isAllField) { | ||
newSettings.lenient(lenientSet ? settings.lenient() : true); | ||
} | ||
isAllField = defaultFields.size() == 1 && Regex.isMatchAllPattern(defaultFields.get(0)); |
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.
@jimczi Why do we check only the first element here, shouldn't we check all the defaultFields
?
(same applies to all 3 types of queries)
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 agree we should check all elements. However I don't think it's useful to set fields
or the default fields to something like ["*", "field1", "field2"]
but for consistency we should always set the leniency to true if *
is part of the list of fields to query.
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 left some small comments but it looks good @matriv.
if (isAllField) { | ||
newSettings.lenient(lenientSet ? settings.lenient() : true); | ||
} | ||
isAllField = defaultFields.size() == 1 && Regex.isMatchAllPattern(defaultFields.get(0)); |
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 agree we should check all elements. However I don't think it's useful to set fields
or the default fields to something like ["*", "field1", "field2"]
but for consistency we should always set the leniency to true if *
is part of the list of fields to query.
} | ||
assertEquals(11, noMatchNoDocsQueries); | ||
assertThat(disjunctionMaxQuery.getDisjuncts(), hasItems(new TermQuery(new Term(STRING_FIELD_NAME, "hello")), | ||
new TermQuery(new Term(STRING_FIELD_NAME_2, "hello")))); |
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.
Can you also add a test with a single field set on *
?
} | ||
assertEquals(11, noMatchNoDocsQueries); | ||
assertThat(disjunctionMaxQuery.getDisjuncts(), hasItems(new TermQuery(new Term(STRING_FIELD_NAME, "hello")), | ||
new TermQuery(new Term(STRING_FIELD_NAME_2, "hello")))); |
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.
Same here
Also check if `*` is in the list of the default_field but not necessarily as the 1st element.
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.
The main part looks good to me, I left a very small suggestion about testing.
server/src/test/java/org/elasticsearch/index/query/MultiMatchQueryBuilderTests.java
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/index/query/SimpleQueryStringBuilderTests.java
Show resolved
Hide resolved
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.
LGTM
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.
LGTM too
Allow for SimpleQueryString, QueryString and MultiMatchQuery to set the `fields` parameter to the wildcard `*`. If so, set the leniency to `true`, to achieve the same behaviour as from the `"default_field" : "*" setting. Furthermore, check if `*` is in the list of the `default_field` but not necessarily as the 1st element. Closes: #39577 (cherry picked from commit e75ff0c)
Allow for SimpleQueryString, QueryString and MultiMatchQuery to set the `fields` parameter to the wildcard `*`. If so, set the leniency to `true`, to achieve the same behaviour as from the `"default_field" : "*" setting. Furthermore, check if `*` is in the list of the `default_field` but not necessarily as the 1st element. Closes: elastic#39577
Allow for SimpleQueryString, QueryString and MultiMatchQuery
to set the
fields
parameter to the wildcard*
. If so, setthe leniency to
true
, to achieve the same behaviour as from the"default_field" : "*"
setting.Closes: #39577