Skip to content
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

EQL: Adds "fields" request field to the eql request #68962

Merged
merged 6 commits into from
Feb 23, 2021

Conversation

astefan
Copy link
Contributor

@astefan astefan commented Feb 14, 2021

Adds a "fields" section to the body of an eql request, identical to how a _search endpoint handles a "fields" request element.

Addresses #68115.

@elasticmachine elasticmachine added the Team:QL (Deprecated) Meta label for query languages team label Feb 14, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-ql (Team:QL)

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM.

@@ -137,6 +140,9 @@ public void fetchHits(Iterable<List<HitReference>> refs, ActionListener<List<Lis
// the default size is 10 so be sure to change it
// NB:this is different from mget
.size(idQuery.ids().size());
if (fetchFields != null) {
fetchFields.stream().forEach(f -> builder.fetchField(f));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forEach exists directly on List - no need to create the stream.
Also use the method reference : fetchFields.forEach(builder::fetchField)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Thanks.

@@ -61,6 +64,11 @@ public static SearchSourceBuilder sourceBuilder(QueryContainer container, QueryB
// disable the source, as we rely on "fields" API
source.fetchSource(false);

// add the "fields" to be fetched
if (fetchFields != null) {
fetchFields.stream().forEach(f -> source.fetchField(f));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above re: forEach & method reference.

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Left a question regarding serialisation.

@@ -324,6 +363,12 @@ public void writeTo(StreamOutput out) throws IOException {
if (out.getVersion().onOrAfter(Version.V_7_10_0)) { // TODO: Remove after backport
out.writeString(resultPosition);
}
if (out.getVersion().onOrAfter(Version.V_7_12_0)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be V_8_0_0 for now and once backported switch to V_8_0_0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matriv @bpintea Actually, the new test I added - https://github.com/elastic/elasticsearch/pull/68962/files#diff-7e1220049ee22470c58a915155e9d9bd3ef7742523a6bfd0e71b8c463df3e638 - won't let me use V_8_0_0 because a version 8.0 of ES should be compatible with the latest version 7.x of ES (which is 7.12). And the test in AbstractBWCSerializationTestCase is doing serialization and deserialization on 7.12 and compares the deserialized instance with the original (8.0) instance. And the test fails, because the two instances should be equal.

@@ -106,6 +115,11 @@ public EqlSearchRequest(StreamInput in) throws IOException {
if (in.getVersion().onOrAfter(Version.V_7_10_0)) {
resultPosition = in.readString();
}
if (in.getVersion().onOrAfter(Version.V_7_12_0)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple more instances of this test. But I assume it's fine, since there aren't bwc integration tests like we have for SQL, so this should work?

Copy link
Contributor

@bpintea bpintea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -56,6 +59,13 @@ protected NamedXContentRegistry xContentRegistry() {
@Override
protected EqlSearchRequest createTestInstance() {
try {
List<FieldAndFormat> randomFetchFields = new ArrayList<>();
for (int j = 0; j < randomIntBetween(0, 5); j++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still getting you a random number of iterations, but the exit condition is (likely) going to change with each iteration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Nice catch!

@@ -106,6 +115,11 @@ public EqlSearchRequest(StreamInput in) throws IOException {
if (in.getVersion().onOrAfter(Version.V_7_10_0)) {
resultPosition = in.readString();
}
if (in.getVersion().onOrAfter(Version.V_7_12_0)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple more instances of this test. But I assume it's fine, since there aren't bwc integration tests like we have for SQL, so this should work?

@astefan
Copy link
Contributor Author

astefan commented Feb 15, 2021

@elasticmachine run elasticsearch-ci/2

@astefan
Copy link
Contributor Author

astefan commented Feb 15, 2021

@elasticmachine update branch

@astefan
Copy link
Contributor Author

astefan commented Feb 25, 2021

CC @jrodewig. Sorry for the delay.

@jrodewig
Copy link
Contributor

No worries. Thanks @astefan. I'll work on a related docs PR for these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants