Skip to content

Commit 39e9d88

Browse files
committed
Throw exception if multiple messages in document
1 parent 526fef1 commit 39e9d88

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/patternedtext/PatternedTextFieldMapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.apache.lucene.document.FieldType;
1212
import org.apache.lucene.document.SortedSetDocValuesField;
1313
import org.apache.lucene.index.IndexOptions;
14+
import org.apache.lucene.index.IndexableField;
1415
import org.apache.lucene.util.BytesRef;
1516
import org.elasticsearch.common.util.FeatureFlag;
1617
import org.elasticsearch.index.IndexVersion;
@@ -132,6 +133,11 @@ protected void parseCreateField(DocumentParserContext context) throws IOExceptio
132133
return;
133134
}
134135

136+
var existingValue = context.doc().getField(fieldType().name());
137+
if (existingValue != null) {
138+
throw new IllegalArgumentException("Multiple values are not allowed for field [" + fieldType().name() + "].");
139+
}
140+
135141
// Parse template and args.
136142
PatternedTextValueProcessor.Parts parts = PatternedTextValueProcessor.split(value);
137143

x-pack/plugin/logsdb/src/yamlRestTest/resources/rest-api-spec/test/patternedtext/10_basic.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,5 +308,26 @@ tsdb:
308308
"dimension" : "a"
309309
foo: "Apache Lucene powers Elasticsearch"
310310

311+
---
312+
Multiple values:
313+
- do:
314+
indices.create:
315+
index: test1
316+
body:
317+
mappings:
318+
properties:
319+
foo:
320+
type: patterned_text
321+
- do:
322+
catch: bad_request
323+
index:
324+
index: test1
325+
id: "1"
326+
body: {
327+
"foo": [
328+
"Found 5 errors for service [cheddar1]",
329+
"[2020-08-18T00:58:56] Found 123 errors for service [cheddar1]"
330+
]
331+
}
311332

312333

0 commit comments

Comments
 (0)