Skip to content

Commit 79ca586

Browse files
authored
EQL: Disable field extraction for returned events (#52884)
Return the whole source of matching events
1 parent d03ac93 commit 79ca586

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/EqlIT.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@
2323
import org.apache.http.client.methods.HttpPut;
2424
import org.elasticsearch.client.eql.EqlSearchRequest;
2525
import org.elasticsearch.client.eql.EqlSearchResponse;
26+
import org.elasticsearch.common.settings.Settings;
27+
import org.elasticsearch.common.time.DateUtils;
28+
import org.elasticsearch.index.IndexSettings;
2629
import org.junit.Before;
2730

31+
import java.time.format.DateTimeFormatter;
32+
2833
import static org.hamcrest.Matchers.equalTo;
2934

3035
public class EqlIT extends ESRestHighLevelClientTestCase {
@@ -35,7 +40,6 @@ public void setupRemoteClusterConfig() throws Exception {
3540
}
3641

3742
public void testBasicSearch() throws Exception {
38-
3943
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index/_doc/1");
4044
doc1.setJsonEntity("{\"event_subtype_full\": \"already_running\", " +
4145
"\"event_type\": \"process\", " +
@@ -61,4 +65,33 @@ public void testBasicSearch() throws Exception {
6165
assertNotNull(response.hits().events());
6266
assertThat(response.hits().events().size(), equalTo(1));
6367
}
68+
69+
public void testLargeMapping() throws Exception {
70+
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index/_doc/1");
71+
// use more exact fields (dates) than the default to verify that retrieval works and requesting doc values
72+
// would fail
73+
int PASS_DEFAULT_DOC_VALUES = IndexSettings.MAX_DOCVALUE_FIELDS_SEARCH_SETTING.get(Settings.EMPTY) + 50;
74+
String now = DateUtils.nowWithMillisResolution().format(DateTimeFormatter.ISO_DATE_TIME);
75+
StringBuilder sb = new StringBuilder();
76+
sb.append("{");
77+
for (int i = 0; i < PASS_DEFAULT_DOC_VALUES; i++) {
78+
sb.append("\"datetime" + i + "\":\"" + now + "\"");
79+
sb.append(",");
80+
}
81+
sb.append("\"event_type\": \"process\",");
82+
sb.append("\"serial_event_id\": 1");
83+
sb.append("}");
84+
doc1.setJsonEntity(sb.toString());
85+
86+
client().performRequest(doc1);
87+
client().performRequest(new Request(HttpPost.METHOD_NAME, "/_refresh"));
88+
89+
90+
EqlClient eql = highLevelClient().eql();
91+
EqlSearchRequest request = new EqlSearchRequest("index", "process where true");
92+
EqlSearchResponse response = execute(request, eql::search, eql::searchAsync);
93+
assertNotNull(response);
94+
assertNotNull(response.hits());
95+
assertThat(response.hits().events().size(), equalTo(1));
96+
}
6497
}

x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/execution/search/SourceGenerator.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.elasticsearch.search.fetch.StoredFieldsContext;
1111
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
1212
import org.elasticsearch.xpack.eql.querydsl.container.QueryContainer;
13-
import org.elasticsearch.xpack.ql.execution.search.QlSourceBuilder;
1413

1514
import java.util.List;
1615

@@ -41,14 +40,7 @@ public static SearchSourceBuilder sourceBuilder(QueryContainer container, QueryB
4140
final SearchSourceBuilder source = new SearchSourceBuilder();
4241
source.query(finalQuery);
4342

44-
QlSourceBuilder sortBuilder = new QlSourceBuilder();
45-
// Iterate through all the columns requested, collecting the fields that
46-
// need to be retrieved from the result documents
47-
48-
// NB: the sortBuilder takes care of eliminating duplicates
49-
container.fields().forEach(f -> f.v1().collectFields(sortBuilder));
50-
sortBuilder.build(source);
51-
optimize(sortBuilder, source);
43+
source.fetchSource(FetchSourceContext.FETCH_SOURCE);
5244

5345
// set fetch size
5446
if (size != null) {
@@ -62,22 +54,9 @@ public static SearchSourceBuilder sourceBuilder(QueryContainer container, QueryB
6254
return source;
6355
}
6456

65-
private static void optimize(QlSourceBuilder qlSource, SearchSourceBuilder builder) {
66-
if (qlSource.noSource()) {
67-
disableSource(builder);
68-
}
69-
}
70-
7157
private static void optimize(QueryContainer query, SearchSourceBuilder builder) {
7258
if (query.shouldTrackHits()) {
7359
builder.trackTotalHits(true);
7460
}
7561
}
76-
77-
private static void disableSource(SearchSourceBuilder builder) {
78-
builder.fetchSource(FetchSourceContext.DO_NOT_FETCH_SOURCE);
79-
if (builder.storedFields() == null) {
80-
builder.storedFields(NO_STORED_FIELD);
81-
}
82-
}
8362
}

x-pack/plugin/eql/src/test/java/org/elasticsearch/xpack/eql/planner/QueryFolderTests.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ public void testBasicPlan() {
5151
// test query term
5252
assertThat(query, containsString("\"term\":{\"event_type\":{\"value\":\"process\""));
5353
// test field source extraction
54-
assertThat(query, containsString("\"_source\":{\"includes\":["));
55-
assertThat(query, containsString("\"pid\""));
56-
// test docvalue extraction
57-
assertThat(query, containsString("{\"field\":\"command_line\"}"));
58-
assertThat(query, containsString("{\"field\":\"timestamp\",\"format\":\"epoch_millis\"}"));
54+
assertThat(query, containsString("\"_source\":{\"includes\":[],\"excludes\":[]"));
5955
}
6056
}

0 commit comments

Comments
 (0)