-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Shortcut query phase using the results of other shards #51852
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
53 commits
Select commit
Hold shift + click to select a range
28fa23b
Always rewrite search shard request outside of the search thread pool
jimczi 534b552
add serialization test
jimczi c02f352
iter
jimczi 010ec08
Merge branch 'master' into rewrite_shard_request_no_rejection
jimczi f5684ec
fix bwc issue
jimczi 0acf244
address review
jimczi 6016fa4
adapt test
jimczi a058127
fix test
jimczi 8534ed2
fix topNSize when size is reset to 0
jimczi 27cdf19
add more comments
jimczi a313d1d
Merge branch 'master' into rewrite_shard_request_no_rejection
jimczi 662972c
more review
jimczi 76e90a2
initial commit
jimczi 7eb98fb
Merge branch 'master' into distributed_time_sort
jimczi ac0451c
iter
jimczi d0ae658
iter
jimczi c6747e6
Merge branch 'rewrite_shard_request_no_rejection' into distributed_ti…
jimczi 30b3bcb
iter2
jimczi 961c2cd
remove unrelated change
jimczi d04a16d
Merge branch 'master' into distributed_time_sort
jimczi af20421
fix last merge
jimczi 291f742
fix rest test
jimczi 71876e4
another fix
jimczi b8aa0e2
Merge branch 'master' into distributed_time_sort
jimczi db4b44f
address review
jimczi bd927bd
adapt serialization version before backport
jimczi bf8ebde
address review
jimczi 30173b6
Merge branch 'master' into distributed_time_sort
jimczi 2e19865
fix comparator
jimczi 8eae737
fix topdocs size
jimczi ea5727e
Merge branch 'master' into distributed_time_sort
jimczi f50ec90
iter
jimczi ee2591f
Merge branch 'master' into distributed_time_sort
jimczi 4ec6a6c
fix final merge when some shard responses have their size artifically…
jimczi 09bfb09
check style
jimczi 5e268c6
return topfielddocs if the shard search request rewrites the size to 0
jimczi 2307e73
Merge branch 'master' into distributed_time_sort
jimczi ae1b278
Replace raw sort values with formatted ones to handle date and date_n…
jimczi bfd2c72
Merge branch 'master' into distributed_time_sort
jimczi 6489ffe
fix unset of track total hits in distributed search
jimczi 73aa681
fix compilation test after merging with master
jimczi b2504e6
Merge branch 'master' into distributed_time_sort
jimczi 36bec99
fix partial comment
jimczi 74b8bea
Merge branch 'master' into distributed_time_sort
jimczi 7a54222
iter
jimczi abda530
Add stricter assertions
jimczi 06cbc19
checkstyle
jimczi 74c5d99
Merge branch 'master' into distributed_time_sort
jimczi e526147
Merge branch 'master' into distributed_time_sort
jimczi 14542f0
sort values can be integers and floats (_doc and _score)
jimczi 8ad41c2
fix test to handle accepted raw sort format
jimczi 270533c
Merge branch 'master' into distributed_time_sort
jimczi e4e8b02
fix compil after master merge
jimczi 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
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
111 changes: 111 additions & 0 deletions
111
server/src/main/java/org/elasticsearch/action/search/BottomSortValuesCollector.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,111 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch 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. | ||
*/ | ||
|
||
package org.elasticsearch.action.search; | ||
|
||
import org.apache.lucene.search.FieldComparator; | ||
import org.apache.lucene.search.FieldDoc; | ||
import org.apache.lucene.search.SortField; | ||
import org.apache.lucene.search.TopFieldDocs; | ||
import org.elasticsearch.search.DocValueFormat; | ||
import org.elasticsearch.search.SearchSortValuesAndFormats; | ||
|
||
/** | ||
* Utility class to keep track of the bottom doc's sort values in a distributed search. | ||
*/ | ||
class BottomSortValuesCollector { | ||
private final int topNSize; | ||
private final SortField[] sortFields; | ||
private final FieldComparator[] comparators; | ||
private final int[] reverseMuls; | ||
|
||
private volatile long totalHits; | ||
private volatile SearchSortValuesAndFormats bottomSortValues; | ||
|
||
BottomSortValuesCollector(int topNSize, SortField[] sortFields) { | ||
this.topNSize = topNSize; | ||
this.comparators = new FieldComparator[sortFields.length]; | ||
this.reverseMuls = new int[sortFields.length]; | ||
this.sortFields = sortFields; | ||
for (int i = 0; i < sortFields.length; i++) { | ||
comparators[i] = sortFields[i].getComparator(1, i); | ||
reverseMuls[i] = sortFields[i].getReverse() ? -1 : 1; | ||
} | ||
} | ||
|
||
long getTotalHits() { | ||
return totalHits; | ||
} | ||
|
||
/** | ||
* @return The best bottom sort values consumed so far. | ||
*/ | ||
SearchSortValuesAndFormats getBottomSortValues() { | ||
return bottomSortValues; | ||
} | ||
|
||
synchronized void consumeTopDocs(TopFieldDocs topDocs, DocValueFormat[] sortValuesFormat) { | ||
totalHits += topDocs.totalHits.value; | ||
if (validateShardSortFields(topDocs.fields) == false) { | ||
return; | ||
} | ||
|
||
FieldDoc shardBottomDoc = extractBottom(topDocs); | ||
if (shardBottomDoc == null) { | ||
return; | ||
} | ||
if (bottomSortValues == null | ||
|| compareValues(shardBottomDoc.fields, bottomSortValues.getRawSortValues()) < 0) { | ||
bottomSortValues = new SearchSortValuesAndFormats(shardBottomDoc.fields, sortValuesFormat); | ||
} | ||
} | ||
|
||
/** | ||
* @return <code>false</code> if the provided {@link SortField} array differs | ||
* from the initial {@link BottomSortValuesCollector#sortFields}. | ||
*/ | ||
private boolean validateShardSortFields(SortField[] shardSortFields) { | ||
for (int i = 0; i < shardSortFields.length; i++) { | ||
if (shardSortFields[i].equals(sortFields[i]) == false) { | ||
// ignore shards response that would make the sort incompatible | ||
// (e.g.: mixing keyword/numeric or long/double). | ||
// TODO: we should fail the entire request because the topdocs | ||
// merge will likely fail later but this is not possible with | ||
// the current async logic that only allows shard failures here. | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private FieldDoc extractBottom(TopFieldDocs topDocs) { | ||
return topNSize > 0 && topDocs.scoreDocs.length == topNSize ? | ||
(FieldDoc) topDocs.scoreDocs[topNSize-1] : null; | ||
} | ||
|
||
private int compareValues(Object[] v1, Object[] v2) { | ||
for (int i = 0; i < v1.length; i++) { | ||
int cmp = reverseMuls[i] * comparators[i].compareValues(v1[i], v2[i]); | ||
if (cmp != 0) { | ||
return cmp; | ||
} | ||
} | ||
return 0; | ||
} | ||
} |
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
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
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.