-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Teach _search to read search time mappings #59316
Closed
nik9000
wants to merge
20
commits into
elastic:feature/runtime_fields
from
nik9000:search_time_mapping
+380
−11
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1533428
Teach _search to read search time mappings
nik9000 dc70b42
Itr
nik9000 1938a0e
Itr
nik9000 9d8e4b3
Tests
nik9000 5a44788
Merge branch 'feature/runtime_fields' into search_time_mapping
nik9000 7346b8b
Parse plz
nik9000 4891bda
Precommit
nik9000 77f35cb
Fix test
nik9000 2011791
Fix test
nik9000 2b9b34c
Revert some stuff
nik9000 0546dc2
Revert
nik9000 a86ffaa
WIP
nik9000 87bf5bf
Merge branch 'feature/runtime_fields' into search_time_mapping
nik9000 8aeab2f
Merge branch 'feature/runtime_fields' into search_time_mapping
nik9000 3c12ed0
itr
nik9000 09aa1f4
iter
nik9000 65a5326
Tests
nik9000 27628d9
Merge branch 'feature/runtime_fields' into search_time_mapping
nik9000 acefc5d
Oops
nik9000 394ba8f
sub-objects
nik9000 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
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
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
package org.elasticsearch.search.builder; | ||
|
||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.common.Booleans; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.ParseField; | ||
|
@@ -62,6 +63,7 @@ | |
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder; | ||
|
@@ -107,6 +109,7 @@ public final class SearchSourceBuilder implements Writeable, ToXContentObject, R | |
public static final ParseField SEARCH_AFTER = new ParseField("search_after"); | ||
public static final ParseField COLLAPSE = new ParseField("collapse"); | ||
public static final ParseField SLICE = new ParseField("slice"); | ||
public static final ParseField RUNTIME_MAPPINGS = new ParseField("runtime_mappings"); | ||
|
||
public static SearchSourceBuilder fromXContent(XContentParser parser) throws IOException { | ||
return fromXContent(parser, true); | ||
|
@@ -185,6 +188,8 @@ public static HighlightBuilder highlight() { | |
|
||
private CollapseBuilder collapse = null; | ||
|
||
private Map<String, Object> runtimeMappings; | ||
|
||
/** | ||
* Constructs a new search source builder. | ||
*/ | ||
|
@@ -239,6 +244,10 @@ public SearchSourceBuilder(StreamInput in) throws IOException { | |
sliceBuilder = in.readOptionalWriteable(SliceBuilder::new); | ||
collapse = in.readOptionalWriteable(CollapseBuilder::new); | ||
trackTotalHitsUpTo = in.readOptionalInt(); | ||
if (in.getVersion().onOrAfter(Version.V_8_0_0)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a TODO to update the version once the branch is merged? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
// TODO update version after backporting runtime fields | ||
runtimeMappings = in.readMap(); | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -293,6 +302,16 @@ public void writeTo(StreamOutput out) throws IOException { | |
out.writeOptionalWriteable(sliceBuilder); | ||
out.writeOptionalWriteable(collapse); | ||
out.writeOptionalInt(trackTotalHitsUpTo); | ||
if (out.getVersion().onOrAfter(Version.V_8_0_0)) { | ||
// TODO update version after backporting runtime fields | ||
out.writeMap(runtimeMappings); | ||
} else { | ||
if (runtimeMappings != null && false == runtimeMappings.isEmpty()) { | ||
throw new IllegalArgumentException( | ||
"[" + RUNTIME_MAPPINGS.getPreferredName() + "] are not supported on nodes older than 8.0.0" | ||
); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -895,6 +914,21 @@ public List<String> stats() { | |
return stats; | ||
} | ||
|
||
/** | ||
* Extra runtime field mappings. | ||
*/ | ||
public SearchSourceBuilder runtimeMappings(Map<String, Object> runtimeMappings) { | ||
this.runtimeMappings = runtimeMappings; | ||
return this; | ||
} | ||
|
||
/** | ||
* Extra runtime field mappings. | ||
*/ | ||
public Map<String, Object> runtimeMappings() { | ||
return runtimeMappings; | ||
} | ||
|
||
public SearchSourceBuilder ext(List<SearchExtBuilder> searchExtBuilders) { | ||
this.extBuilders = Objects.requireNonNull(searchExtBuilders, "searchExtBuilders must not be null"); | ||
return this; | ||
|
@@ -996,6 +1030,7 @@ private SearchSourceBuilder shallowCopy(QueryBuilder queryBuilder, QueryBuilder | |
rewrittenBuilder.version = version; | ||
rewrittenBuilder.seqNoAndPrimaryTerm = seqNoAndPrimaryTerm; | ||
rewrittenBuilder.collapse = collapse; | ||
rewrittenBuilder.runtimeMappings = runtimeMappings; | ||
return rewrittenBuilder; | ||
} | ||
|
||
|
@@ -1104,6 +1139,8 @@ public void parseXContent(XContentParser parser, boolean checkTrailingTokens) th | |
sliceBuilder = SliceBuilder.fromXContent(parser); | ||
} else if (COLLAPSE.match(currentFieldName, parser.getDeprecationHandler())) { | ||
collapse = CollapseBuilder.fromXContent(parser); | ||
} else if (RUNTIME_MAPPINGS.match(currentFieldName, parser.getDeprecationHandler())) { | ||
runtimeMappings = parser.map(); | ||
} else { | ||
throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", | ||
parser.getTokenLocation()); | ||
|
@@ -1300,6 +1337,10 @@ public XContentBuilder innerToXContent(XContentBuilder builder, Params params) t | |
if (collapse != null) { | ||
builder.field(COLLAPSE.getPreferredName(), collapse); | ||
} | ||
|
||
if (runtimeMappings != null && false == runtimeMappings.isEmpty()) { | ||
builder.field(RUNTIME_MAPPINGS.getPreferredName(), runtimeMappings); | ||
} | ||
return builder; | ||
} | ||
|
||
|
@@ -1551,7 +1592,8 @@ public boolean equals(Object obj) { | |
&& Objects.equals(profile, other.profile) | ||
&& Objects.equals(extBuilders, other.extBuilders) | ||
&& Objects.equals(collapse, other.collapse) | ||
&& Objects.equals(trackTotalHitsUpTo, other.trackTotalHitsUpTo); | ||
&& Objects.equals(trackTotalHitsUpTo, other.trackTotalHitsUpTo) | ||
&& Objects.equals(runtimeMappings, other.runtimeMappings); | ||
} | ||
|
||
@Override | ||
|
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.
Can you expand on why we need this? I was expecting that alias or objects would be caught anyways by your checks below, that only runtime fields can be defined.
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.
This should allow us to collect the sub-mappers under objects. I do need to make sure there is a test for though.