-
Notifications
You must be signed in to change notification settings - Fork 25.2k
more_like_this query to throw an error if the like fields is not provided #40632
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
Conversation
…ided With the removal of the `_all` field the `mlt` query cannot infer a field name to use to analyze the provided (un)like text if the `fields` parameter is not explicitly set in the query and the `index.query.default_field` is not changed in the index settings (by default it is set to `*`). For this reason the like text is ignored and queries are only built from the provided document ids. This change fixes this bug by throwing an error if the fields option is not set and the `index.query.default_field` is equals to `*`. The error is thrown only if like or unlike texts are provided in the query.
Pinging @elastic/es-search |
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 change and the implementation make sense to me. Left one question though, also some additional tests seem to need to be adapted as well.
if (moreLikeFields.size() == 1 | ||
&& moreLikeFields.get(0).equals("*") | ||
&& (likeTexts.length > 0 || unlikeTexts.length > 0)) { | ||
throw new IllegalArgumentException("[more_like_this] query cannot infer the field to analyze the free text, " + |
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 error seems to be breaking MoreLikeThisQueryBuilderTests#testToQuery and also occasionally #testMustRewrite. Probably something in the test setup needs to be changed.
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.
Thanks good catch, I changed the test to not create invalid builders now that we have this restriction.
} finally { | ||
// Reset the default value | ||
context.getIndexSettings().updateIndexMetaData( | ||
newIndexMeta("index", |
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.
Just out of curiosity: why does the default need to get changed back? I was under the impression the context doesn't get reused? between different tests? If that is not the case, maybe the context should contain a copy of the index settings so changes to it don't affect other tests. This might be something to adress in another issue though if adressing it here is too involved.
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.
We update the settings for the created index that is shared among all tests in this class so we need to reset the value at the end. The query shard context is created for each test method but the index is static.
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.
Interesting, I think it would be good to change the test setup so this is something we don't have to worry about when writing tests. Probably worth a separate issue though.
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 it's ok to share the same index on all tests. We can maybe restore the default value of the index settings after each test but it's very uncommon to change a setting in a query builder test so I don't think it's worth the change.
@elasticmachine run elasticsearch-ci/1 |
@elasticmachine run elasticsearch-ci/2 |
@cbuescher I pushed some changes to address your feedback, can you take another look ? |
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 thanks for the update, LGTM
…ided (#40632) With the removal of the `_all` field the `mlt` query cannot infer a field name to use to analyze the provided (un)like text if the `fields` parameter is not explicitly set in the query and the `index.query.default_field` is not changed in the index settings (by default it is set to `*`). For this reason the like text is ignored and queries are only built from the provided document ids. This change fixes this bug by throwing an error if the fields option is not set and the `index.query.default_field` is equals to `*`. The error is thrown only if like or unlike texts are provided in the query.
…ided (elastic#40632) With the removal of the `_all` field the `mlt` query cannot infer a field name to use to analyze the provided (un)like text if the `fields` parameter is not explicitly set in the query and the `index.query.default_field` is not changed in the index settings (by default it is set to `*`). For this reason the like text is ignored and queries are only built from the provided document ids. This change fixes this bug by throwing an error if the fields option is not set and the `index.query.default_field` is equals to `*`. The error is thrown only if like or unlike texts are provided in the query.
With the removal of the
_all
field themlt
query cannot infer a field nameto use to analyze the provided (un)like text if the
fields
parameter is notexplicitly set in the query and the
index.query.default_field
is not changedin the index settings (by default it is set to
*
). For this reason the like textis ignored and queries are only built from the provided document ids.
This change fixes this bug by throwing an error if the fields option is not set
and the
index.query.default_field
is equals to*
. The error is thrown onlyif like or unlike texts are provided in the query.