[8.6] Fix Enterprise Search document search bug in indices without position 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)](https://github.com/elastic/kibana/pull/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":"63422879+kderusso@users.noreply.github.com"},"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
<42973632+kibanamachine@users.noreply.github.com>","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
<42973632+kibanamachine@users.noreply.github.com>","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
<42973632+kibanamachine@users.noreply.github.com>","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 <63422879+kderusso@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2023-01-05 15:09:18 -05:00 committed by GitHub
parent 5213e30e49
commit c29cc3f37a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 6 deletions

View file

@ -49,11 +49,14 @@ To debug Kea state in-browser, Kea recommends [Redux Devtools](https://v2.keajs.
Documentation: https://www.elastic.co/guide/en/kibana/current/development-tests.html#_unit_testing
Jest tests can be run directly from the `x-pack/plugins/enterprise_search` folder. This also works for any subfolders or subcomponents.
Jest tests can be run from the root kibana directory, however, since the tests take so long to run you will likely want to apply the appropriate Jest configuration file to test only your changes. For example:
- `x-pack/plugins/enterprise_search/common/jest.config.js`
- `x-pack/plugins/enterprise_search/public/jest.config.js`
- `x-pack/plugins/enterprise_search/server/jest.config.js`
```bash
yarn test:jest
yarn test:jest --watch
yarn test:jest --config {YOUR_JEST_CONFIG_FILE}
yarn test:jest --config {YOUR_JEST_CONFIG_FILE} --watch
```
Unfortunately coverage collection does not work as automatically, and requires using our handy jest.sh script if you want to run tests on a specific file or folder and only get coverage numbers for that file or folder:

View file

@ -87,7 +87,28 @@ describe('fetchSearchResults lib function', () => {
expect(mockClient.asCurrentUser.search).toHaveBeenCalledWith({
from: DEFAULT_FROM_VALUE,
index: indexName,
q: JSON.stringify(query),
q: query,
size: ENTERPRISE_SEARCH_DOCUMENTS_DEFAULT_DOC_COUNT,
});
});
it('should escape quotes in queries and return results with hits', async () => {
mockClient.asCurrentUser.search.mockImplementation(
() => regularSearchResultsResponse as SearchResponseBody
);
await expect(
fetchSearchResults(
mockClient as unknown as IScopedClusterClient,
indexName,
'"yellow banana"'
)
).resolves.toEqual(regularSearchResultsResponse);
expect(mockClient.asCurrentUser.search).toHaveBeenCalledWith({
from: DEFAULT_FROM_VALUE,
index: indexName,
q: '\\"yellow banana\\"',
size: ENTERPRISE_SEARCH_DOCUMENTS_DEFAULT_DOC_COUNT,
});
});
@ -120,7 +141,7 @@ describe('fetchSearchResults lib function', () => {
expect(mockClient.asCurrentUser.search).toHaveBeenCalledWith({
from: DEFAULT_FROM_VALUE,
index: indexName,
q: JSON.stringify(query),
q: query,
size: ENTERPRISE_SEARCH_DOCUMENTS_DEFAULT_DOC_COUNT,
});
});

View file

@ -21,7 +21,7 @@ export const fetchSearchResults = async (
from,
index: indexName,
size,
...(!!query ? { q: JSON.stringify(query) } : {}),
...(!!query ? { q: query.replace(/"/g, '\\"') } : {}),
});
return results;
};