Skip to content

Commit 29e1bf9

Browse files
Mikep86ioanatia
andauthored
Make semantic text part of the text family (#119792)
Co-authored-by: Ioana Tagirta <[email protected]>
1 parent 7245632 commit 29e1bf9

File tree

11 files changed

+171
-120
lines changed

11 files changed

+171
-120
lines changed

docs/changelog/119792.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 119792
2+
summary: Make semantic text part of the text family
3+
area: Search
4+
type: enhancement
5+
issues: []

server/src/main/java/org/elasticsearch/index/search/MatchQueryParser.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
import org.elasticsearch.index.mapper.PlaceHolderFieldMapper;
4444
import org.elasticsearch.index.mapper.TextFieldMapper;
4545
import org.elasticsearch.index.mapper.TextSearchInfo;
46+
import org.elasticsearch.index.query.MatchBoolPrefixQueryBuilder;
47+
import org.elasticsearch.index.query.MatchPhrasePrefixQueryBuilder;
48+
import org.elasticsearch.index.query.MatchPhraseQueryBuilder;
4649
import org.elasticsearch.index.query.SearchExecutionContext;
4750
import org.elasticsearch.index.query.ZeroTermsQueryOption;
4851
import org.elasticsearch.lucene.analysis.miscellaneous.DisableGraphAttribute;
@@ -63,24 +66,26 @@ public enum Type implements Writeable {
6366
/**
6467
* The text is analyzed and terms are added to a boolean query.
6568
*/
66-
BOOLEAN(0),
69+
BOOLEAN(0, org.elasticsearch.index.query.MatchQueryBuilder.NAME),
6770
/**
6871
* The text is analyzed and used as a phrase query.
6972
*/
70-
PHRASE(1),
73+
PHRASE(1, MatchPhraseQueryBuilder.NAME),
7174
/**
7275
* The text is analyzed and used in a phrase query, with the last term acting as a prefix.
7376
*/
74-
PHRASE_PREFIX(2),
77+
PHRASE_PREFIX(2, MatchPhrasePrefixQueryBuilder.NAME),
7578
/**
7679
* The text is analyzed, terms are added to a boolean query with the last term acting as a prefix.
7780
*/
78-
BOOLEAN_PREFIX(3);
81+
BOOLEAN_PREFIX(3, MatchBoolPrefixQueryBuilder.NAME);
7982

8083
private final int ordinal;
84+
private final String queryName;
8185

82-
Type(int ordinal) {
86+
Type(int ordinal, String queryName) {
8387
this.ordinal = ordinal;
88+
this.queryName = queryName;
8489
}
8590

8691
public static Type readFromStream(StreamInput in) throws IOException {
@@ -93,6 +98,10 @@ public static Type readFromStream(StreamInput in) throws IOException {
9398
throw new ElasticsearchException("unknown serialized type [" + ord + "]");
9499
}
95100

101+
public String getQueryName() {
102+
return queryName;
103+
}
104+
96105
@Override
97106
public void writeTo(StreamOutput out) throws IOException {
98107
out.writeVInt(this.ordinal);
@@ -207,11 +216,23 @@ public Query parse(Type type, String fieldName, Object value) throws IOException
207216
IllegalArgumentException iae;
208217
if (fieldType instanceof PlaceHolderFieldMapper.PlaceHolderFieldType) {
209218
iae = new IllegalArgumentException(
210-
"Field [" + fieldType.name() + "] of type [" + fieldType.typeName() + "] in legacy index does not support match queries"
219+
"Field ["
220+
+ fieldType.name()
221+
+ "] of type ["
222+
+ fieldType.typeName()
223+
+ "] in legacy index does not support "
224+
+ type.getQueryName()
225+
+ " queries"
211226
);
212227
} else {
213228
iae = new IllegalArgumentException(
214-
"Field [" + fieldType.name() + "] of type [" + fieldType.typeName() + "] does not support match queries"
229+
"Field ["
230+
+ fieldType.name()
231+
+ "] of type ["
232+
+ fieldType.typeName()
233+
+ "] does not support "
234+
+ type.getQueryName()
235+
+ " queries"
215236
);
216237
}
217238
if (lenient) {

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/EsqlSpecTestCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ public final void test() throws Throwable {
173173

174174
protected void shouldSkipTest(String testName) throws IOException {
175175
if (testCase.requiredCapabilities.contains("semantic_text_type")
176-
|| testCase.requiredCapabilities.contains("semantic_text_aggregations")) {
176+
|| testCase.requiredCapabilities.contains("semantic_text_aggregations")
177+
|| testCase.requiredCapabilities.contains("semantic_text_field_caps")) {
177178
assumeTrue("Inference test service needs to be supported for semantic_text", supportsInferenceTestService());
178179
}
179180
checkCapabilities(adminClient(), testFeatureService, testName, testCase);

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,9 @@ private static Void convertUnsupported(String s) {
495495
for (Type value : Type.values()) {
496496
LOOKUP.put(value.name(), value);
497497
}
498+
// Types with a different field caps family type
499+
LOOKUP.put("SEMANTIC_TEXT", TEXT);
500+
498501
// widen smaller types
499502
LOOKUP.put("SHORT", INTEGER);
500503
LOOKUP.put("BYTE", INTEGER);

x-pack/plugin/esql/qa/testFixtures/src/main/resources/match-function.csv-spec

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,14 +601,15 @@ emp_no_bool:boolean
601601
testMatchWithSemanticText
602602
required_capability: match_function
603603
required_capability: semantic_text_type
604+
required_capability: semantic_text_field_caps
604605

605606
from semantic_text
606607
| where match(semantic_text_field, "something")
607608
| keep semantic_text_field
608609
| sort semantic_text_field asc
609610
;
610611

611-
semantic_text_field:semantic_text
612+
semantic_text_field:text
612613
all we have to decide is what to do with the time that is given to us
613614
be excellent to each other
614615
live long and prosper
@@ -617,32 +618,35 @@ live long and prosper
617618
testMatchWithSemanticTextAndKeyword
618619
required_capability: match_function
619620
required_capability: semantic_text_type
621+
required_capability: semantic_text_field_caps
620622

621623
from semantic_text
622624
| where match(semantic_text_field, "something") AND match(host, "host1")
623625
| keep semantic_text_field, host
624626
;
625627

626-
semantic_text_field:semantic_text | host:keyword
627-
live long and prosper | host1
628+
semantic_text_field:text | host:keyword
629+
live long and prosper | host1
628630
;
629631

630632
testMatchWithSemanticTextMultiValueField
631633
required_capability: match_function
632634
required_capability: semantic_text_type
635+
required_capability: semantic_text_field_caps
633636

634637
from semantic_text metadata _id
635638
| where match(st_multi_value, "something") AND match(host, "host1")
636639
| keep _id, st_multi_value
637640
;
638641

639-
_id: keyword | st_multi_value:semantic_text
642+
_id: keyword | st_multi_value:text
640643
1 | ["Hello there!", "This is a random value", "for testing purposes"]
641644
;
642645

643646
testMatchWithSemanticTextWithEvalsAndOtherFunctionsAndStats
644647
required_capability: match_function
645648
required_capability: semantic_text_type
649+
required_capability: semantic_text_field_caps
646650

647651
from semantic_text
648652
| where qstr("description:some*")
@@ -659,12 +663,13 @@ testMatchWithSemanticTextAndKql
659663
required_capability: match_function
660664
required_capability: semantic_text_type
661665
required_capability: kql_function
666+
required_capability: semantic_text_field_caps
662667

663668
from semantic_text
664669
| where kql("host:host1") AND match(semantic_text_field, "something")
665670
| KEEP host, semantic_text_field
666671
;
667672

668-
host:keyword | semantic_text_field:semantic_text
673+
host:keyword | semantic_text_field:text
669674
"host1" | live long and prosper
670675
;

x-pack/plugin/esql/qa/testFixtures/src/main/resources/match-operator.csv-spec

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -611,14 +611,15 @@ emp_no_bool:boolean
611611
testMatchWithSemanticText
612612
required_capability: match_operator_colon
613613
required_capability: semantic_text_type
614+
required_capability: semantic_text_field_caps
614615

615616
from semantic_text
616617
| where semantic_text_field:"something"
617618
| keep semantic_text_field
618619
| sort semantic_text_field asc
619620
;
620621

621-
semantic_text_field:semantic_text
622+
semantic_text_field:text
622623
all we have to decide is what to do with the time that is given to us
623624
be excellent to each other
624625
live long and prosper
@@ -627,32 +628,35 @@ live long and prosper
627628
testMatchWithSemanticTextAndKeyword
628629
required_capability: match_operator_colon
629630
required_capability: semantic_text_type
631+
required_capability: semantic_text_field_caps
630632

631633
from semantic_text
632634
| where semantic_text_field:"something" AND host:"host1"
633635
| keep semantic_text_field, host
634636
;
635637

636-
semantic_text_field:semantic_text | host:keyword
637-
live long and prosper | host1
638+
semantic_text_field:text | host:keyword
639+
live long and prosper | host1
638640
;
639641

640642
testMatchWithSemanticTextMultiValueField
641643
required_capability: match_operator_colon
642644
required_capability: semantic_text_type
645+
required_capability: semantic_text_field_caps
643646

644647
from semantic_text metadata _id
645648
| where st_multi_value:"something" AND match(host, "host1")
646649
| keep _id, st_multi_value
647650
;
648651

649-
_id: keyword | st_multi_value:semantic_text
652+
_id: keyword | st_multi_value:text
650653
1 | ["Hello there!", "This is a random value", "for testing purposes"]
651654
;
652655

653656
testMatchWithSemanticTextWithEvalsAndOtherFunctionsAndStats
654657
required_capability: match_operator_colon
655658
required_capability: semantic_text_type
659+
required_capability: semantic_text_field_caps
656660

657661
from semantic_text
658662
| where qstr("description:some*")
@@ -669,12 +673,13 @@ testMatchWithSemanticTextAndKql
669673
required_capability: match_operator_colon
670674
required_capability: semantic_text_type
671675
required_capability: kql_function
676+
required_capability: semantic_text_field_caps
672677

673678
from semantic_text
674679
| where kql("host:host1") AND semantic_text_field:"something"
675680
| KEEP host, semantic_text_field
676681
;
677682

678-
host:keyword | semantic_text_field:semantic_text
683+
host:keyword | semantic_text_field:text
679684
"host1" | live long and prosper
680685
;

0 commit comments

Comments
 (0)