Skip to content

Commit f9344bf

Browse files
committed
More yaml test updates
1 parent 03b9fde commit f9344bf

File tree

8 files changed

+72
-336
lines changed

8 files changed

+72
-336
lines changed

x-pack/plugin/mapper-patterned-text/src/main/java/org/elasticsearch/xpack/patternedtext/PatternedTextDocValues.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ String lookupOrdAsString(long l) throws IOException {
5656
List<String> args = new ArrayList<>(argsCount);
5757
if (argsCount > 0) {
5858
var mergedArgs = argsDocValues.lookupOrd(argsDocValues.nextOrd());
59-
PatternedTextValueProcessor.addRemainingArgs(args, mergedArgs.utf8ToString());
59+
PatternedTextValueProcessor.decodeRemainingArgs(args, mergedArgs.utf8ToString());
6060
}
6161
return PatternedTextValueProcessor.merge(new PatternedTextValueProcessor.Parts(template, args));
6262
}

x-pack/plugin/mapper-patterned-text/src/main/java/org/elasticsearch/xpack/patternedtext/PatternedTextFieldMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private PatternedTextFieldMapper(
114114

115115
@Override
116116
public Map<String, NamedAnalyzer> indexAnalyzers() {
117-
return Map.of(mappedFieldType.name(), indexAnalyzer, fieldType().templateFieldName(), indexAnalyzer);
117+
return Map.of(mappedFieldType.name(), indexAnalyzer);
118118
}
119119

120120
@Override
@@ -140,7 +140,7 @@ protected void parseCreateField(DocumentParserContext context) throws IOExceptio
140140

141141
// Add args doc_values
142142
if (parts.args().isEmpty() == false) {
143-
String remainingArgs = PatternedTextValueProcessor.mergeRemainingArgs(parts, 0);
143+
String remainingArgs = PatternedTextValueProcessor.encodeRemainingArgs(parts);
144144
context.doc().add(new SortedSetDocValuesField(fieldType().argsFieldName(), new BytesRef(remainingArgs)));
145145
}
146146
}

x-pack/plugin/mapper-patterned-text/src/main/java/org/elasticsearch/xpack/patternedtext/PatternedTextFieldType.java

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import org.apache.lucene.index.Term;
1414
import org.apache.lucene.queries.intervals.Intervals;
1515
import org.apache.lucene.queries.intervals.IntervalsSource;
16-
import org.apache.lucene.search.BooleanClause;
17-
import org.apache.lucene.search.BooleanQuery;
1816
import org.apache.lucene.search.ConstantScoreQuery;
1917
import org.apache.lucene.search.FieldExistsQuery;
2018
import org.apache.lucene.search.FuzzyQuery;
@@ -35,8 +33,6 @@
3533
import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
3634
import org.elasticsearch.index.mapper.BlockLoader;
3735
import org.elasticsearch.index.mapper.DocValueFetcher;
38-
import org.elasticsearch.index.mapper.DynamicFieldType;
39-
import org.elasticsearch.index.mapper.MappedFieldType;
4036
import org.elasticsearch.index.mapper.StringFieldType;
4137
import org.elasticsearch.index.mapper.TextFieldMapper;
4238
import org.elasticsearch.index.mapper.TextSearchInfo;
@@ -56,7 +52,7 @@
5652

5753
import static org.elasticsearch.search.aggregations.support.CoreValuesSourceType.KEYWORD;
5854

59-
public class PatternedTextFieldType extends StringFieldType implements DynamicFieldType {
55+
public class PatternedTextFieldType extends StringFieldType {
6056

6157
private static final String TEMPLATE_SUFFIX = ".template";
6258
private static final String ARGS_SUFFIX = ".args";
@@ -65,14 +61,11 @@ public class PatternedTextFieldType extends StringFieldType implements DynamicFi
6561

6662
private final Analyzer indexAnalyzer;
6763
private final TextFieldMapper.TextFieldType textFieldType;
68-
private final TextFieldMapper.TextFieldType templateFieldType;
6964

7065
PatternedTextFieldType(String name, TextSearchInfo tsi, Analyzer indexAnalyzer, boolean isSyntheticSource, Map<String, String> meta) {
7166
super(name, true, false, true, tsi, meta);
7267
this.indexAnalyzer = Objects.requireNonNull(indexAnalyzer);
7368
this.textFieldType = new TextFieldMapper.TextFieldType(name, isSyntheticSource);
74-
this.templateFieldType = new TextFieldMapper.TextFieldType(name + TEMPLATE_SUFFIX, isSyntheticSource);
75-
this.templateFieldType.setFielddata(true); // for aggregations
7669
}
7770

7871
PatternedTextFieldType(String name) {
@@ -85,11 +78,6 @@ public class PatternedTextFieldType extends StringFieldType implements DynamicFi
8578
);
8679
}
8780

88-
@Override
89-
public MappedFieldType getChildFieldType(String path) {
90-
return templateFieldType;
91-
}
92-
9381
@Override
9482
public String typeName() {
9583
return CONTENT_TYPE;
@@ -100,6 +88,11 @@ public String familyTypeName() {
10088
return TextFieldMapper.CONTENT_TYPE;
10189
}
10290

91+
@Override
92+
public boolean isAggregatable() {
93+
return false;
94+
}
95+
10396
@Override
10497
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
10598
return new DocValueFetcher(docValueFormat(format, null), context.getForField(this, FielddataOperation.SEARCH));
@@ -121,14 +114,10 @@ private IOFunction<LeafReaderContext, CheckedIntFunction<List<Object>, IOExcepti
121114
};
122115
}
123116

124-
private Query combinedQuery(Query query, Query templateQuery, SearchExecutionContext context) {
117+
private Query sourceConfirmedQuery(Query query, SearchExecutionContext context) {
125118
// Disable scoring
126119
return new ConstantScoreQuery(
127-
// TODO: skip SourceConfirmedTextQuery when the templateQuery has matches.
128-
new BooleanQuery.Builder().add(
129-
new SourceConfirmedTextQuery(query, getValueFetcherProvider(context), indexAnalyzer),
130-
BooleanClause.Occur.SHOULD
131-
).add(templateQuery, BooleanClause.Occur.SHOULD).build()
120+
new SourceConfirmedTextQuery(query, getValueFetcherProvider(context), indexAnalyzer)
132121
);
133122
}
134123

@@ -234,24 +223,21 @@ public IntervalsSource rangeIntervals(
234223
public Query phraseQuery(TokenStream stream, int slop, boolean enablePosIncrements, SearchExecutionContext queryShardContext)
235224
throws IOException {
236225
final Query textQuery = textFieldType.phraseQuery(stream, slop, enablePosIncrements, queryShardContext);
237-
final Query templateQuery = templateFieldType.phraseQuery(stream, slop, enablePosIncrements, queryShardContext);
238-
return combinedQuery(textQuery, templateQuery, queryShardContext);
226+
return sourceConfirmedQuery(textQuery, queryShardContext);
239227
}
240228

241229
@Override
242230
public Query multiPhraseQuery(TokenStream stream, int slop, boolean enablePositionIncrements, SearchExecutionContext queryShardContext)
243231
throws IOException {
244232
final Query textQuery = textFieldType.multiPhraseQuery(stream, slop, enablePositionIncrements, queryShardContext);
245-
final Query templateQuery = templateFieldType.multiPhraseQuery(stream, slop, enablePositionIncrements, queryShardContext);
246-
return combinedQuery(textQuery, templateQuery, queryShardContext);
233+
return sourceConfirmedQuery(textQuery, queryShardContext);
247234
}
248235

249236
@Override
250237
public Query phrasePrefixQuery(TokenStream stream, int slop, int maxExpansions, SearchExecutionContext queryShardContext)
251238
throws IOException {
252239
final Query textQuery = textFieldType.phrasePrefixQuery(stream, slop, maxExpansions, queryShardContext);
253-
final Query templateQuery = templateFieldType.phrasePrefixQuery(stream, slop, maxExpansions, queryShardContext);
254-
return combinedQuery(textQuery, templateQuery, queryShardContext);
240+
return sourceConfirmedQuery(textQuery, queryShardContext);
255241
}
256242

257243
@Override

x-pack/plugin/mapper-patterned-text/src/main/java/org/elasticsearch/xpack/patternedtext/PatternedTextValueProcessor.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,11 @@ static String merge(Parts parts) {
8181
return builder.toString();
8282
}
8383

84-
static String mergeRemainingArgs(Parts parts, int startOffset) {
85-
StringBuilder builder = new StringBuilder();
86-
for (int i = startOffset; i < parts.args.size(); i++) {
87-
builder.append((i > startOffset) ? SPACE : "").append(parts.args.get(i));
88-
}
89-
return builder.toString();
84+
static String encodeRemainingArgs(Parts parts) {
85+
return String.join(SPACE, parts.args);
9086
}
9187

92-
static void addRemainingArgs(List<String> args, String mergedArgs) {
88+
static void decodeRemainingArgs(List<String> args, String mergedArgs) {
9389
Collections.addAll(args, mergedArgs.split(SPACE));
9490
}
9591

x-pack/plugin/mapper-patterned-text/src/yamlRestTest/resources/rest-api-spec/test/10_basic.yml

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Field caps:
4545
fields: [ foo ]
4646

4747
- match: { fields.foo.text.searchable: true }
48-
- match: { fields.foo.text.aggregatable: true }
48+
- match: { fields.foo.text.aggregatable: false }
4949

5050
---
5151
Exist query:
@@ -267,58 +267,6 @@ Wildcard highlighting:
267267
- match: { hits.hits.0._source.foo: "Found 5 errors for service [cheddar1]" }
268268
- match: { hits.hits.0.highlight.foo.0: "Found <em>5</em> errors for service [cheddar1]" }
269269

270-
---
271-
Terms aggregation:
272-
273-
- do:
274-
search:
275-
index: test
276-
body:
277-
aggs:
278-
term_agg:
279-
terms:
280-
field: foo.text
281-
282-
- match: { hits.total.value: 4 }
283-
- length: { aggregations.term_agg.buckets: 10 }
284-
- match: { aggregations.term_agg.buckets.0.key: apache }
285-
- match: { aggregations.term_agg.buckets.0.doc_count: 3 }
286-
- match: { aggregations.term_agg.buckets.1.key: lucene }
287-
- match: { aggregations.term_agg.buckets.1.doc_count: 3 }
288-
- match: { aggregations.term_agg.buckets.2.key: elasticsearch }
289-
- match: { aggregations.term_agg.buckets.2.doc_count: 2 }
290-
291-
---
292-
synthetic_source:
293-
294-
- do:
295-
indices.create:
296-
index: synthetic_source_test
297-
body:
298-
settings:
299-
index:
300-
mapping.source.mode: synthetic
301-
mappings:
302-
properties:
303-
foo:
304-
type: patterned_text
305-
306-
- do:
307-
index:
308-
index: synthetic_source_test
309-
id: "1"
310-
refresh: true
311-
body:
312-
foo: "Apache Lucene powers Elasticsearch"
313-
314-
- do:
315-
search:
316-
index: synthetic_source_test
317-
- match: { "hits.total.value": 1 }
318-
- match:
319-
hits.hits.0._source:
320-
foo: "Apache Lucene powers Elasticsearch"
321-
322270
---
323271
tsdb:
324272

@@ -360,42 +308,5 @@ tsdb:
360308
"dimension" : "a"
361309
foo: "Apache Lucene powers Elasticsearch"
362310

363-
---
364-
synthetic_source with copy_to:
365-
366-
- do:
367-
indices.create:
368-
index: synthetic_source_test
369-
body:
370-
settings:
371-
index:
372-
mapping.source.mode: synthetic
373-
mappings:
374-
properties:
375-
foo:
376-
type: patterned_text
377-
copy_to: copy
378-
copy:
379-
type: keyword
380-
381-
- do:
382-
index:
383-
index: synthetic_source_test
384-
id: "1"
385-
refresh: true
386-
body:
387-
foo: "Apache Lucene powers Elasticsearch"
388-
389-
- do:
390-
search:
391-
index: synthetic_source_test
392-
body:
393-
fields: ["copy"]
394-
395-
- match: { "hits.total.value": 1 }
396-
- match:
397-
hits.hits.0._source.foo: "Apache Lucene powers Elasticsearch"
398-
- match:
399-
hits.hits.0.fields.copy.0: "Apache Lucene powers Elasticsearch"
400311

401312

x-pack/plugin/mapper-patterned-text/src/yamlRestTest/resources/rest-api-spec/test/20_synthetic_source.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,41 @@ simple:
3636
- match: { hits.hits.1._source.message: "another log message with arg 1234 and arg 5678 and a mixed one ABCD9" }
3737
- match: { hits.hits.2._source.message: "some log message with no arg" }
3838
- match: { hits.hits.3._source.message: "another log message with arg 1234 and arg 8765 and a mixed one ABCD1" }
39+
40+
---
41+
synthetic_source with copy_to:
42+
43+
- do:
44+
indices.create:
45+
index: synthetic_source_test
46+
body:
47+
settings:
48+
index:
49+
mapping.source.mode: synthetic
50+
mappings:
51+
properties:
52+
foo:
53+
type: patterned_text
54+
copy_to: copy
55+
copy:
56+
type: keyword
57+
58+
- do:
59+
index:
60+
index: synthetic_source_test
61+
id: "1"
62+
refresh: true
63+
body:
64+
foo: "another log message with arg 1234 and arg 5678 and a mixed one ABCD9"
65+
66+
- do:
67+
search:
68+
index: synthetic_source_test
69+
body:
70+
fields: ["copy"]
71+
72+
- match: { "hits.total.value": 1 }
73+
- match:
74+
hits.hits.0._source.foo: "another log message with arg 1234 and arg 5678 and a mixed one ABCD9"
75+
- match:
76+
hits.hits.0.fields.copy.0: "another log message with arg 1234 and arg 5678 and a mixed one ABCD9"

x-pack/plugin/mapper-patterned-text/src/yamlRestTest/resources/rest-api-spec/test/30_sort.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@ simple:
99
type: integer
1010
message:
1111
type: patterned_text
12+
some_field:
13+
type: integer
1214

1315
- do:
1416
bulk:
1517
index: test
1618
refresh: true
1719
body:
1820
- '{ "create": { } }'
19-
- '{ "id": 1, "message": "some log message with no arg" }'
21+
- '{ "id": 1, "message": "some log message with no arg", "some_field": 4 }'
2022
- '{ "create": { } }'
21-
- '{ "id": 2, "message": "another log message with arg 1234 and arg 5678 and a mixed one ABCD9" }'
23+
- '{ "id": 2, "message": "another log message with arg 1234 and arg 5678 and a mixed one ABCD9", "some_field": 1 }'
2224
- '{ "create": { } }'
23-
- '{ "id": 3, "message": "some log message with no arg" }'
25+
- '{ "id": 3, "message": "some log message with no arg", "some_field": 2 }'
2426
- '{ "create": { } }'
25-
- '{ "id": 4, "message": "another log message with arg 1234 and arg 8765 and a mixed one ABCD1" }'
27+
- '{ "id": 4, "message": "another log message with arg 1234 and arg 8765 and a mixed one ABCD1", "some_field": 3 }'
2628

2729
- do:
2830
search:
@@ -33,3 +35,13 @@ simple:
3335
- match: { hits.hits.1._source.message: "another log message with arg 1234 and arg 8765 and a mixed one ABCD1" }
3436
- match: { hits.hits.2._source.message: "some log message with no arg" }
3537
- match: { hits.hits.3._source.message: "some log message with no arg" }
38+
39+
- do:
40+
search:
41+
index: test
42+
sort: some_field
43+
44+
- match: { hits.hits.0._source.message: "another log message with arg 1234 and arg 5678 and a mixed one ABCD9" }
45+
- match: { hits.hits.1._source.message: "some log message with no arg" }
46+
- match: { hits.hits.2._source.message: "another log message with arg 1234 and arg 8765 and a mixed one ABCD1" }
47+
- match: { hits.hits.3._source.message: "some log message with no arg" }

0 commit comments

Comments
 (0)