-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Phase 1 of search services #46742
Merged
stacey-gammon
merged 26 commits into
elastic:master
from
stacey-gammon:2019-09-25-np-search-api
Oct 10, 2019
Merged
Phase 1 of search services #46742
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
e9d62d2
Phase 1 of search services
stacey-gammon 1da04ee
First review feedback
lukasolson d2c6787
Merge pull request #11 from lukasolson/np-search-api
stacey-gammon c0d3070
Start on tests
stacey-gammon 6c9a09a
Add functional tests for search explorer
stacey-gammon 83806cc
Add unload and fix ts error
stacey-gammon 606dcc0
Merge branch 'master' of github.com:elastic/kibana into 2019-09-25-np…
stacey-gammon 00a22d6
Add index.test.ts files for coverage completeness
stacey-gammon ba50e95
Adding unit tests
lukasolson 83eab32
Merge pull request #12 from lukasolson/np-search-api
stacey-gammon d75b3e9
use internal route terminology. No reason this should be a public rou…
stacey-gammon 1617ffa
Move search service into data plugin
stacey-gammon 95bde79
Merge branch 'master' of github.com:elastic/kibana into 2019-09-25-np…
stacey-gammon ce571b5
App mount search context needs to be optional
stacey-gammon e5ea60e
Merge branch 'master' of github.com:elastic/kibana into 2019-09-25-np…
stacey-gammon 64de132
Add more unit tests for server stuff
lukasolson 2c6c96f
Merge pull request #13 from lukasolson/np-search-api
stacey-gammon 88e73f6
wip types fix
stacey-gammon e9e75ef
Merge branch 'master' of github.com:elastic/kibana into 2019-09-25-np…
stacey-gammon 83aa47a
fix types for new context container stuff
stacey-gammon 2c9b24c
put back all jest test coverage paths
stacey-gammon 25ec030
address review comments
stacey-gammon 82db4e7
Merge branch 'master' of github.com:elastic/kibana into 2019-09-25-np…
stacey-gammon 8621708
delete the two test files that just tested the instantiation of the s…
stacey-gammon 1678aec
expose search fn on StartContract... tested locally only
stacey-gammon ce0a93f
update mocks to account for new startcontract
stacey-gammon 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export { IEsSearchRequest, IEsSearchResponse, ES_SEARCH_STRATEGY } from './types'; |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { SearchParams, SearchResponse } from 'elasticsearch'; | ||
import { IKibanaSearchRequest, IKibanaSearchResponse } from '../types'; | ||
|
||
export const ES_SEARCH_STRATEGY = 'es'; | ||
|
||
export interface IEsSearchRequest extends IKibanaSearchRequest { | ||
params: SearchParams; | ||
} | ||
|
||
export interface IEsSearchResponse<Hits = unknown> extends IKibanaSearchResponse { | ||
rawResponse: SearchResponse<Hits>; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { ES_SEARCH_STRATEGY } from './es_search'; | ||
|
||
export { IKibanaSearchResponse, IKibanaSearchRequest } from './types'; | ||
|
||
export const DEFAULT_SEARCH_STRATEGY = ES_SEARCH_STRATEGY; | ||
|
||
export { IEsSearchRequest, IEsSearchResponse, ES_SEARCH_STRATEGY } from './es_search'; |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export interface IKibanaSearchResponse { | ||
/** | ||
* Some responses may contain a unique id to identify the request this response came from. | ||
*/ | ||
id?: string; | ||
|
||
/** | ||
* If relevant to the search strategy, return a percentage | ||
* that represents how progress is indicated. | ||
*/ | ||
percentComplete?: number; | ||
|
||
/** | ||
* If relevant to the search strategy, return a total number | ||
* that represents how progress is indicated. | ||
*/ | ||
total?: number; | ||
|
||
/** | ||
* If relevant to the search strategy, return a loaded number | ||
* that represents how progress is indicated. | ||
*/ | ||
loaded?: number; | ||
} | ||
|
||
export interface IKibanaSearchRequest { | ||
/** | ||
* An id can be used to uniquely identify this request. | ||
*/ | ||
id?: string; | ||
|
||
/** | ||
* Optionally tell search strategies to output debug information. | ||
*/ | ||
debug?: boolean; | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# search | ||
|
||
The `search` plugin provides the ability to register search strategies that take in a request | ||
object, and return a response object, of a given shape. | ||
|
||
Both client side search strategies can be registered, as well as server side search strategies. | ||
|
||
The `search` plugin includes two one concrete client side implementations - | ||
`SYNC_SEARCH_STRATEGY` and `ES_SEARCH_STRATEGY` which uses `SYNC_SEARCH_STRATEGY`. There is also one | ||
default server side search strategy, `ES_SEARCH_STRATEGY`. | ||
|
||
Includes the `esSearch` plugin in order to search for data from Elasticsearch using Elasticsearch | ||
DSL. |
69 changes: 69 additions & 0 deletions
69
src/plugins/data/public/search/create_app_mount_context_search.test.ts
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { createAppMountSearchContext } from './create_app_mount_context_search'; | ||
import { from } from 'rxjs'; | ||
|
||
describe('Create app mount search context', () => { | ||
it('Returns search fn when there are no strategies', () => { | ||
const context = createAppMountSearchContext({}); | ||
expect(context.search).toBeDefined(); | ||
}); | ||
|
||
it(`Search throws an error when the strategy doesn't exist`, () => { | ||
const context = createAppMountSearchContext({}); | ||
expect(() => context.search({}, {}, 'noexist').toPromise()).toThrowErrorMatchingInlineSnapshot( | ||
`"Strategy with name noexist does not exist"` | ||
); | ||
}); | ||
|
||
it(`Search fn is called on appropriate strategy name`, done => { | ||
const context = createAppMountSearchContext({ | ||
mysearch: search => | ||
Promise.resolve({ | ||
search: () => from(Promise.resolve({ percentComplete: 98 })), | ||
}), | ||
anothersearch: search => | ||
Promise.resolve({ | ||
search: () => from(Promise.resolve({ percentComplete: 0 })), | ||
}), | ||
}); | ||
|
||
context.search({}, {}, 'mysearch').subscribe(response => { | ||
expect(response).toEqual({ percentComplete: 98 }); | ||
done(); | ||
}); | ||
}); | ||
|
||
it(`Search fn is called with the passed in request object`, done => { | ||
const context = createAppMountSearchContext({ | ||
mysearch: search => { | ||
return Promise.resolve({ | ||
search: request => { | ||
expect(request).toEqual({ greeting: 'hi' }); | ||
return from(Promise.resolve({})); | ||
}, | ||
}); | ||
}, | ||
}); | ||
context | ||
.search({ greeting: 'hi' } as any, {}, 'mysearch') | ||
.subscribe(response => {}, () => {}, done); | ||
}); | ||
}); |
57 changes: 57 additions & 0 deletions
57
src/plugins/data/public/search/create_app_mount_context_search.ts
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { mergeMap } from 'rxjs/operators'; | ||
import { from } from 'rxjs'; | ||
import { ISearchAppMountContext } from './i_search_app_mount_context'; | ||
import { ISearchGeneric } from './i_search'; | ||
import { | ||
TSearchStrategiesMap, | ||
ISearchStrategy, | ||
TSearchStrategyProviderEnhanced, | ||
} from './i_search_strategy'; | ||
import { TStrategyTypes } from './strategy_types'; | ||
import { DEFAULT_SEARCH_STRATEGY } from '../../common/search'; | ||
|
||
export const createAppMountSearchContext = ( | ||
searchStrategies: TSearchStrategiesMap | ||
): ISearchAppMountContext => { | ||
const getSearchStrategy = <K extends TStrategyTypes = typeof DEFAULT_SEARCH_STRATEGY>( | ||
strategyName?: K | ||
): Promise<ISearchStrategy<K>> => { | ||
const strategyProvider = searchStrategies[ | ||
strategyName ? strategyName : DEFAULT_SEARCH_STRATEGY | ||
] as TSearchStrategyProviderEnhanced<K> | undefined; | ||
if (!strategyProvider) { | ||
throw new Error(`Strategy with name ${strategyName} does not exist`); | ||
} | ||
return strategyProvider(search); | ||
}; | ||
|
||
const search: ISearchGeneric = (request, options, strategyName) => { | ||
const strategyPromise = getSearchStrategy(strategyName); | ||
return from(strategyPromise).pipe( | ||
mergeMap(strategy => { | ||
return strategy.search(request, options); | ||
}) | ||
); | ||
}; | ||
|
||
return { search }; | ||
}; |
43 changes: 43 additions & 0 deletions
43
src/plugins/data/public/search/es_search/es_search_service.test.ts
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { coreMock } from '../../../../../core/public/mocks'; | ||
import { EsSearchService } from './es_search_service'; | ||
import { CoreSetup } from '../../../../../core/public'; | ||
import { searchSetupMock } from '../mocks'; | ||
|
||
describe('ES search strategy service', () => { | ||
let service: EsSearchService; | ||
let mockCoreSetup: MockedKeys<CoreSetup>; | ||
const opaqueId = Symbol(); | ||
|
||
beforeEach(() => { | ||
service = new EsSearchService({ opaqueId }); | ||
mockCoreSetup = coreMock.createSetup(); | ||
}); | ||
|
||
describe('setup()', () => { | ||
it('registers the ES search strategy', async () => { | ||
service.setup(mockCoreSetup, { | ||
search: searchSetupMock, | ||
}); | ||
expect(searchSetupMock.registerSearchStrategyProvider).toBeCalled(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
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.
why import both, or why even have searchService function, all it does is
new SearchService(params)
?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.
Copied the
plugin
way of doing things (this was its own separate plugin so this was theindex.ts
file, at the plugin level, this isexport plugin...
, here I renamed itexport searchService ...
). Not necessary except for conformity. It is pretty silly when you take it outside of the plugin level. I can remove.