-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add blockloader to patterned_text to support ESQL #134093
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
parkertimmins
merged 7 commits into
elastic:main
from
parkertimmins:parker/patterned-text-esql
Sep 4, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
498a43f
Setup esql blockloader for pattern_text
parkertimmins 3f182d8
remove changes used for debugging
parkertimmins 3cd7d84
[CI] Auto commit changes from spotless
3aa135f
Add explanation of BytesRef encodings
parkertimmins 62c0ed9
Rename BytesRefsFromBinary to BytesRefsFromCustomBinary
parkertimmins 2328dc7
Rename BytesRefsFromSimpleBinary to BytesRefsFromBinary
parkertimmins 6ed4a6f
Merge branch 'main' into parker/patterned-text-esql
parkertimmins 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
40 changes: 40 additions & 0 deletions
40
.../src/main/java/org/elasticsearch/xpack/logsdb/patternedtext/PatternedTextBlockLoader.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,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.logsdb.patternedtext; | ||
|
||
import org.apache.lucene.index.LeafReaderContext; | ||
import org.elasticsearch.index.mapper.BlockDocValuesReader; | ||
|
||
import java.io.IOException; | ||
|
||
public class PatternedTextBlockLoader extends BlockDocValuesReader.DocValuesBlockLoader { | ||
|
||
private final String templateFieldName; | ||
private final String argsFieldName; | ||
private final String argsInfoFieldName; | ||
|
||
PatternedTextBlockLoader(String templateFieldName, String argsFieldName, String argsInfoFieldName) { | ||
this.templateFieldName = templateFieldName; | ||
this.argsFieldName = argsFieldName; | ||
this.argsInfoFieldName = argsInfoFieldName; | ||
} | ||
|
||
@Override | ||
public BytesRefBuilder builder(BlockFactory factory, int expectedCount) { | ||
return factory.bytesRefs(expectedCount); | ||
} | ||
|
||
@Override | ||
public AllReader reader(LeafReaderContext context) throws IOException { | ||
var docValues = PatternedTextDocValues.from(context.reader(), templateFieldName, argsFieldName, argsInfoFieldName); | ||
if (docValues == null) { | ||
return new ConstantNullsReader(); | ||
} | ||
return new BlockDocValuesReader.BytesRefsFromBinary(docValues); | ||
} | ||
} |
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
108 changes: 108 additions & 0 deletions
108
x-pack/plugin/logsdb/src/yamlRestTest/resources/rest-api-spec/test/patternedtext/40_esql.yml
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,108 @@ | ||
--- | ||
setup: | ||
- requires: | ||
cluster_features: [ "mapper.patterned_text" ] | ||
reason: "patterned_text mappings are used in this test" | ||
|
||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
settings: | ||
index: | ||
mapping.source.mode: synthetic | ||
mappings: | ||
properties: | ||
"@timestamp": | ||
type: date | ||
message: | ||
type: patterned_text | ||
# defaults to index_options: docs | ||
|
||
- do: | ||
bulk: | ||
index: test | ||
refresh: true | ||
body: | ||
- { "index": { "_id": "1" } } | ||
- { "@timestamp": "2025-07-17T00:00:01Z" } | ||
- { "index": { "_id": "2" } } | ||
- { "message": "Found 5 errors for service [cheddar1]", "@timestamp": "2025-07-17T00:00:02Z" } | ||
# template_id: mOVsnxlxdac | ||
- { "index": { "_id": "3" } } | ||
- { "message": "[2020-08-18T00:58:56] Found 123 errors for service [cheddar1]", "@timestamp": "2025-07-17T00:00:03Z" } | ||
# template_id: 1l_PtCLQ5xY | ||
- { "index": { "_id": "4" } } | ||
- { "message": "Found some errors for cheddar data service", "@timestamp": "2025-07-17T00:00:04Z"} | ||
# template_id: k-2qtjujOCw | ||
- { "index": { "_id": "5" } } | ||
- { "message": "Found 123 errors for service [gorgonzola-24]", "@timestamp": "2025-07-17T00:00:05Z" } | ||
# template_id: mOVsnxlxdac | ||
|
||
--- | ||
teardown: | ||
- do: | ||
indices.delete: | ||
index: test | ||
|
||
--- | ||
"Simple from": | ||
- do: | ||
esql.query: | ||
body: | ||
query: 'FROM test | SORT @timestamp | KEEP message, message.template_id | LIMIT 10' | ||
|
||
- match: {columns.0.name: "message"} | ||
- match: {columns.0.type: "text"} | ||
- match: {columns.1.name: "message.template_id"} | ||
- match: {columns.1.type: "keyword"} | ||
|
||
- length: {values: 5} | ||
- match: {values.0.0: null } | ||
- match: {values.0.1: null } | ||
- match: {values.1.0: "Found 5 errors for service [cheddar1]" } | ||
- match: {values.1.1: "mOVsnxlxdac" } | ||
- match: {values.2.0: "[2020-08-18T00:58:56] Found 123 errors for service [cheddar1]" } | ||
- match: {values.2.1: "1l_PtCLQ5xY" } | ||
- match: {values.3.0: "Found some errors for cheddar data service" } | ||
- match: {values.3.1: "k-2qtjujOCw" } | ||
- match: {values.4.0: "Found 123 errors for service [gorgonzola-24]" } | ||
- match: {values.4.1: "mOVsnxlxdac" } | ||
|
||
--- | ||
"match query": | ||
- do: | ||
esql.query: | ||
body: | ||
query: 'FROM test | WHERE MATCH(message, "gorgonzola-24") | KEEP message | LIMIT 10' | ||
|
||
- length: {values: 1} | ||
- match: {values.0.0: "Found 123 errors for service [gorgonzola-24]" } | ||
|
||
--- | ||
"match phrase query": | ||
- do: | ||
esql.query: | ||
body: | ||
query: 'FROM test | WHERE MATCH_PHRASE(message, "123 errors") | SORT @timestamp | KEEP message | LIMIT 10' | ||
|
||
- length: {values: 2} | ||
- match: {values.0.0: "[2020-08-18T00:58:56] Found 123 errors for service [cheddar1]" } | ||
- match: {values.1.0: "Found 123 errors for service [gorgonzola-24]" } | ||
|
||
--- | ||
"template_id stats": | ||
- do: | ||
esql.query: | ||
body: | ||
query: 'FROM test | STATS count(*) BY message.template_id | SORT message.template_id | LIMIT 10' | ||
|
||
- length: {values: 4} | ||
- match: {values.0.0: 1 } | ||
- match: {values.0.1: "1l_PtCLQ5xY" } | ||
- match: {values.1.0: 1 } | ||
- match: {values.1.1: "k-2qtjujOCw" } | ||
- match: {values.2.0: 2 } | ||
- match: {values.2.1: "mOVsnxlxdac" } | ||
- match: {values.3.0: 1 } | ||
- match: {values.3.1: null } |
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
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.
Should this be updated to be
patterned_text
? This comes from the familyType, which is text. So I think leaving as text is correct 🤔