-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Migrate OpenSearchBackend and related search functionality to the new Java client #24946
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
Merged
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
bbee6a3
switch views/backend to new client
moesterheld 5c18b1d
introduce MutableSearchRequestBuilder
moesterheld 8d4e3c9
remove TODO
moesterheld 484e42e
add javadoc
moesterheld cba7662
missing license header
moesterheld c88d90f
fix timezone
moesterheld 33680c7
fix aggregation name
moesterheld 222974d
fix time zone id
moesterheld c8ddb20
better exception message
moesterheld 39f3869
Merge branch 'refs/heads/master' into os3/search-backend
moesterheld 11aef96
change to MutableNamedAggregationBuilder
moesterheld ead68c0
minor fixes
moesterheld 646e6d0
return value as float
moesterheld a80a9c1
Merge branch 'refs/heads/master' into os3/search-backend
moesterheld bd7d9c2
Fix empty index handling
todvora 4a5eac9
Merge branch 'master' into os3/search-backend
moesterheld ed82fdf
defensively copy mutable lists, add unit test
moesterheld d87b76a
code cleanup
moesterheld 8b35839
Add integration test for search type aggregation isolation
moesterheld 882d51a
do not set indices when none are returned
moesterheld 1e8c2f6
close JsonWriter
moesterheld 55c2bee
remove TODO
moesterheld faad167
replace null checks with Optional
moesterheld 6b7bf33
replace null check with Optional
moesterheld 4d9259f
replace null check with optional
moesterheld 67083c0
replace null check with Optional
moesterheld bc6d8cf
remove unused class
moesterheld 399b9a1
add missing asserts
moesterheld 9eded13
change Exception to RuntimeException
moesterheld fcf2ec3
add missing value handling
moesterheld 4592e2c
replace null check with Optional
moesterheld 1e12509
Merge branch 'master' into os3/search-backend
todvora f6a5272
add percentiles handler functionality
moesterheld a0bb9e0
Merge remote-tracking branch 'origin/os3/search-backend' into os3/sea…
moesterheld 0f10a4a
remove unused code
todvora 1c042e1
replace null check with Optional
moesterheld 74c6796
Merge remote-tracking branch 'origin/os3/search-backend' into os3/sea…
moesterheld e8b6111
Merge branch 'master' into os3/search-backend
todvora d50fc5e
safer resource closing
todvora e1bf297
code cleanup
todvora a954560
Merge branch 'master' into os3/search-backend
todvora 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 hidden or 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 hidden or 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
233 changes: 233 additions & 0 deletions
233
...rch3/src/main/java/org/graylog/storage/opensearch3/views/MutableSearchRequestBuilder.java
This file contains hidden or 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,233 @@ | ||
| /* | ||
| * Copyright (C) 2020 Graylog, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the Server Side Public License, version 1, | ||
| * as published by MongoDB, Inc. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * Server Side Public License for more details. | ||
| * | ||
| * You should have received a copy of the Server Side Public License | ||
| * along with this program. If not, see | ||
| * <http://www.mongodb.com/licensing/server-side-public-license>. | ||
| */ | ||
|
|
||
| package org.graylog.storage.opensearch3.views; | ||
|
|
||
| import org.graylog.storage.opensearch3.views.searchtypes.pivot.MutableNamedAggregationBuilder; | ||
| import org.opensearch.client.opensearch._types.ExpandWildcard; | ||
| import org.opensearch.client.opensearch._types.FieldValue; | ||
| import org.opensearch.client.opensearch._types.SortOptions; | ||
| import org.opensearch.client.opensearch._types.Time; | ||
| import org.opensearch.client.opensearch._types.query_dsl.Query; | ||
| import org.opensearch.client.opensearch.core.SearchRequest; | ||
| import org.opensearch.client.opensearch.core.search.Highlight; | ||
| import org.opensearch.client.opensearch.core.search.SourceConfig; | ||
| import org.opensearch.client.opensearch.core.search.TrackHits; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Wrapper for SearchRequest.Builder. | ||
| * All builders in the new client are immutable, write-only and cannot be built more than once. | ||
| * Since we are mutating a reference to the builder in the handlers, we need to be able to read fields | ||
| * that are already set (e.g. to check the type or add to the existing query). Also, we need to be able to | ||
| * copy an existing builder without building and using toBuilder(). | ||
| * This class provides the structure for this. | ||
| */ | ||
| public class MutableSearchRequestBuilder { | ||
|
|
||
| Query query; | ||
| Integer from; | ||
| Integer size; | ||
| TrackHits trackTotalHits; | ||
| List<String> indices; | ||
| Boolean allowNoIndices; | ||
| Boolean ignoreUnavailable; | ||
| List<ExpandWildcard> expandWildcards; | ||
| Time cancelAfterTimeInterval; | ||
| String preference; | ||
| List<SortOptions> sort; | ||
| SourceConfig source; | ||
| Highlight highlight; | ||
| List<MutableNamedAggregationBuilder> aggregations = new ArrayList<>(); | ||
| List<FieldValue> searchAfter; | ||
|
|
||
| public MutableSearchRequestBuilder query(Query query) { | ||
| this.query = query; | ||
| return this; | ||
| } | ||
|
|
||
| public Query query() { | ||
| return query; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder from(Integer from) { | ||
| this.from = from; | ||
| return this; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder size(Integer size) { | ||
| this.size = size; | ||
| return this; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder trackTotalHits(TrackHits trackTotalHits) { | ||
| this.trackTotalHits = trackTotalHits; | ||
| return this; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder index(List<String> indices) { | ||
| this.indices = indices; | ||
| return this; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder allowNoIndices(Boolean allowNoIndices) { | ||
| this.allowNoIndices = allowNoIndices; | ||
| return this; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder ignoreUnavailable(Boolean ignoreUnavailable) { | ||
| this.ignoreUnavailable = ignoreUnavailable; | ||
| return this; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder expandWildcards(ExpandWildcard... expandWildcards) { | ||
| this.expandWildcards = Arrays.asList(expandWildcards); | ||
| return this; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder expandWildcards(List<ExpandWildcard> expandWildcards) { | ||
| this.expandWildcards = expandWildcards; | ||
| return this; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder cancelAfterTimeInterval(Time cancelAfterTimeInterval) { | ||
| this.cancelAfterTimeInterval = cancelAfterTimeInterval; | ||
| return this; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder preference(String preference) { | ||
| this.preference = preference; | ||
| return this; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder sort(List<SortOptions> sort) { | ||
| this.sort = sort; | ||
| return this; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder sort(SortOptions... sort) { | ||
| if (this.sort == null) { | ||
| this.sort = new ArrayList<>(); | ||
| } | ||
| this.sort.addAll(Arrays.asList(sort)); | ||
| return this; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder source(SourceConfig source) { | ||
| this.source = source; | ||
| return this; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder highlight(Highlight highlight) { | ||
| this.highlight = highlight; | ||
| return this; | ||
| } | ||
|
|
||
| public Highlight highlight() { | ||
| return highlight; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder aggregations(List<MutableNamedAggregationBuilder> aggregations) { | ||
| this.aggregations = aggregations; | ||
| return this; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder aggregation(MutableNamedAggregationBuilder aggregation) { | ||
| this.aggregations.add(aggregation); | ||
| return this; | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder searchAfter(List<FieldValue> searchAfter) { | ||
| this.searchAfter = searchAfter; | ||
| return this; | ||
| } | ||
|
|
||
| SearchRequest build() { | ||
| return SearchRequest.of(b -> { | ||
| if (query != null) { | ||
| b.query(query); | ||
| } | ||
| if (from != null) { | ||
| b.from(from); | ||
| } | ||
| if (size != null) { | ||
| b.size(size); | ||
| } | ||
| if (trackTotalHits != null) { | ||
| b.trackTotalHits(trackTotalHits); | ||
| } | ||
| if (indices != null) { | ||
| b.index(indices); | ||
| } | ||
| if (allowNoIndices != null) { | ||
| b.allowNoIndices(allowNoIndices); | ||
| } | ||
| if (ignoreUnavailable != null) { | ||
| b.ignoreUnavailable(ignoreUnavailable); | ||
| } | ||
| if (expandWildcards != null) { | ||
| b.expandWildcards(expandWildcards); | ||
| } | ||
| if (sort != null) { | ||
| b.sort(sort); | ||
| } | ||
| if (source != null) { | ||
| b.source(source); | ||
| } | ||
| if (highlight != null) { | ||
| b.highlight(highlight); | ||
| } | ||
| if (aggregations != null) { | ||
| aggregations.forEach(aggregation -> { | ||
| b.aggregations(aggregation.getName(), aggregation.build()); | ||
| }); | ||
| } | ||
| if (searchAfter != null) { | ||
| b.searchAfter(searchAfter); | ||
| } | ||
| return b; | ||
| }); | ||
| } | ||
|
|
||
| public MutableSearchRequestBuilder copy() { | ||
| final MutableSearchRequestBuilder copy = new MutableSearchRequestBuilder() | ||
| .query(query) | ||
| .from(from) | ||
| .size(size) | ||
| .trackTotalHits(trackTotalHits) | ||
| .index(indices) | ||
| .allowNoIndices(allowNoIndices) | ||
| .ignoreUnavailable(ignoreUnavailable) | ||
| .expandWildcards(expandWildcards) | ||
| .cancelAfterTimeInterval(cancelAfterTimeInterval) | ||
| .preference(preference) | ||
| .source(source) | ||
| .highlight(highlight) | ||
| .searchAfter(searchAfter); | ||
| copy.aggregations = new ArrayList<>(aggregations); | ||
| copy.sort = sort != null ? new ArrayList<>(sort) : null; | ||
| return copy; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return build().toJsonString(); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.