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

Fix Enterprise Search document search bug in indices without position data indexed #148397

Merged

Conversation

kderusso
Copy link
Member

@kderusso kderusso commented Jan 4, 2023

Summary

Fixes a bug where some searches including spaces would error in certain Enterprise Search indices that don't support multi-match queries in indexed metadata.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@kderusso kderusso added bug Fixes for quality problems that affect the customer experience release_note:skip Skip the PR/issue when compiling release notes Team:EnterpriseSearch auto-backport-next v8.6.0 v8.7.0 v7.17.9 labels Jan 4, 2023
@kderusso kderusso requested a review from a team January 4, 2023 14:40
@@ -21,7 +21,7 @@ export const fetchSearchResults = async (
from,
index: indexName,
size,
...(!!query ? { q: JSON.stringify(query) } : {}),
...(!!query ? { q: query.replace(/"/g, '\\"') } : {}),
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm good with this, but should we do any follow-up to ensure the query string is sanitized further?

Copy link
Member Author

Choose a reason for hiding this comment

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

@TattdCodeMonkey That's a great question. Did you have anything specific in mind?

@sphilipse seemed to think that was sufficient because you can't really inject anything into the query at that point plus it's already behind authorization. I really dislike the idea of ad-hoc manual safety String mutations for several reasons. We could consider adding a new issue to re-do the search form so that Stringify doesn't force everything to use multi-match, but I'm not really sure what the priority is. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

@kderusso The call is a query_string query, right? Could you describe how the multi-word query fails due to the index not supporting multi-match, e.g. show the error message? Maybe we can fix it in a different way.

My concern is putting the expression in quotes forces a phrase match, which differs from the actual full text matching experience (OR semantics by default). But I agree this is low priority.

Copy link
Member Author

Choose a reason for hiding this comment

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

@demjened Can you please help me better understand your concern here? JSON.stringify was quoting the query and forcing a multi-match query to be run. This removes this default behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I thought query was already coming in quoted from the UI. But then why the need for .replace()? Can't we just pass q: query as-is?

Copy link
Member

Choose a reason for hiding this comment

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

Users can still input a quote in the front-end, which will force a multi-match if we don't escape them.

Quick question: do we also need to escape single quotes, or only double quotes?

Copy link
Member Author

Choose a reason for hiding this comment

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

@sphilipse I have verified that single quotes don't need to be escaped, using them doesn't error.

@demjened If we use double quotes it will force the multi-match phrase query and error. Escaping them solves this.

Copy link
Contributor

@demjened demjened left a comment

Choose a reason for hiding this comment

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

LGTM, 1 minor comment

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@kderusso kderusso merged commit 07a19f1 into elastic:main Jan 4, 2023
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 4, 2023
… data indexed (elastic#148397)

## Summary

Fixes a bug where some searches including spaces would error in certain
Enterprise Search indices that don't support multi-match queries in
indexed metadata.

### Checklist

Delete any items that are not applicable to this PR.

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

Co-authored-by: kibanamachine <[email protected]>
(cherry picked from commit 07a19f1)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 4, 2023
… data indexed (elastic#148397)

## Summary

Fixes a bug where some searches including spaces would error in certain
Enterprise Search indices that don't support multi-match queries in
indexed metadata.

### Checklist

Delete any items that are not applicable to this PR.

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

Co-authored-by: kibanamachine <[email protected]>
(cherry picked from commit 07a19f1)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
7.17 Backport failed because of merge conflicts
8.5
8.6

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 148397

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Jan 4, 2023
…sition data indexed (#148397) (#148410)

# Backport

This will backport the following commits from `main` to `8.5`:
- [Fix Enterprise Search document search bug in indices without position
data indexed (#148397)](#148397)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Kathleen
DeRusso","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-01-04T18:08:59Z","message":"Fix
Enterprise Search document search bug in indices without position data
indexed (#148397)\n\n## Summary\r\n\r\nFixes a bug where some searches
including spaces would error in certain\r\nEnterprise Search indices
that don't support multi-match queries in\r\nindexed
metadata.\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"07a19f12d278ccf03a2a586f3bcef98f9d6f289c","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:EnterpriseSearch","auto-backport-next","v8.6.0","v8.7.0","v7.17.9"],"number":148397,"url":"https://github.com/elastic/kibana/pull/148397","mergeCommit":{"message":"Fix
Enterprise Search document search bug in indices without position data
indexed (#148397)\n\n## Summary\r\n\r\nFixes a bug where some searches
including spaces would error in certain\r\nEnterprise Search indices
that don't support multi-match queries in\r\nindexed
metadata.\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"07a19f12d278ccf03a2a586f3bcef98f9d6f289c"}},"sourceBranch":"main","suggestedTargetBranches":["8.6","7.17"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/148397","number":148397,"mergeCommit":{"message":"Fix
Enterprise Search document search bug in indices without position data
indexed (#148397)\n\n## Summary\r\n\r\nFixes a bug where some searches
including spaces would error in certain\r\nEnterprise Search indices
that don't support multi-match queries in\r\nindexed
metadata.\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"07a19f12d278ccf03a2a586f3bcef98f9d6f289c"}},{"branch":"7.17","label":"v7.17.9","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Kathleen DeRusso <[email protected]>
@sphilipse sphilipse removed the v7.17.9 label Jan 5, 2023
kibanamachine added a commit that referenced this pull request Jan 5, 2023
…sition data indexed (#148397) (#148411)

# Backport

This will backport the following commits from `main` to `8.6`:
- [Fix Enterprise Search document search bug in indices without position
data indexed (#148397)](#148397)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Kathleen
DeRusso","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-01-04T18:08:59Z","message":"Fix
Enterprise Search document search bug in indices without position data
indexed (#148397)\n\n## Summary\r\n\r\nFixes a bug where some searches
including spaces would error in certain\r\nEnterprise Search indices
that don't support multi-match queries in\r\nindexed
metadata.\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"07a19f12d278ccf03a2a586f3bcef98f9d6f289c","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:EnterpriseSearch","auto-backport-next","v8.6.0","v8.7.0","v7.17.9"],"number":148397,"url":"https://github.com/elastic/kibana/pull/148397","mergeCommit":{"message":"Fix
Enterprise Search document search bug in indices without position data
indexed (#148397)\n\n## Summary\r\n\r\nFixes a bug where some searches
including spaces would error in certain\r\nEnterprise Search indices
that don't support multi-match queries in\r\nindexed
metadata.\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"07a19f12d278ccf03a2a586f3bcef98f9d6f289c"}},"sourceBranch":"main","suggestedTargetBranches":["8.6","7.17"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/148397","number":148397,"mergeCommit":{"message":"Fix
Enterprise Search document search bug in indices without position data
indexed (#148397)\n\n## Summary\r\n\r\nFixes a bug where some searches
including spaces would error in certain\r\nEnterprise Search indices
that don't support multi-match queries in\r\nindexed
metadata.\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"07a19f12d278ccf03a2a586f3bcef98f9d6f289c"}},{"branch":"7.17","label":"v7.17.9","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Kathleen DeRusso <[email protected]>
@mistic mistic added v8.6.1 and removed v8.6.0 labels Jan 10, 2023
@mistic
Copy link
Member

mistic commented Jan 10, 2023

The backport was not included on v8.6.0 at it happened after the build candidate. Changing the label to v8.6.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport-next bug Fixes for quality problems that affect the customer experience release_note:skip Skip the PR/issue when compiling release notes Team:EnterpriseSearch v8.5.4 v8.6.1 v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants