Skip to content

Commit f02d15c

Browse files
authored
Fix NPE in SemanticTextHighlighter (#129509) (#129586)
If the model settings is null then the field is guaranteed to not have any indexed content. Closes #129501
1 parent 74bc9d4 commit f02d15c

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

docs/changelog/129509.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 129509
2+
summary: Fix NPE in `SemanticTextHighlighter`
3+
area: Search
4+
type: bug
5+
issues:
6+
- 129501

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/highlight/SemanticTextHighlighter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public HighlightField highlight(FieldHighlightContext fieldContext) throws IOExc
7474
return null;
7575
}
7676
SemanticTextFieldType fieldType = (SemanticTextFieldType) fieldContext.fieldType;
77-
if (fieldType.getEmbeddingsField() == null) {
77+
if (fieldType.getModelSettings() == null || fieldType.getEmbeddingsField() == null) {
7878
// nothing indexed yet
7979
return null;
8080
}

x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/90_semantic_text_highlighter.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ setup:
6060
body:
6161
type: semantic_text
6262
inference_id: dense-inference-id
63+
another_body:
64+
type: semantic_text
65+
inference_id: dense-inference-id
6366

6467
- do:
6568
index:
@@ -79,6 +82,22 @@ setup:
7982
body: [ "ElasticSearch is an open source, distributed, RESTful, search engine which is built on top of Lucene internally and enjoys all the features it provides.", "You Know, for Search!" ]
8083
refresh: true
8184

85+
---
86+
"Highlighting empty field":
87+
- do:
88+
search:
89+
index: test-dense-index
90+
body:
91+
query:
92+
match_all: {}
93+
highlight:
94+
fields:
95+
another_body: {}
96+
97+
- match: { hits.total.value: 1 }
98+
- match: { hits.hits.0._id: "doc_1" }
99+
- not_exists: hits.hits.0.highlight.another_body
100+
82101
---
83102
"Highlighting using a sparse embedding model":
84103
- do:

x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/90_semantic_text_highlighter_bwc.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,35 @@ setup:
5858
body:
5959
type: semantic_text
6060
inference_id: dense-inference-id
61+
another_body:
62+
type: semantic_text
63+
inference_id: dense-inference-id
64+
65+
---
66+
"Highlighting empty field":
67+
- do:
68+
index:
69+
index: test-dense-index
70+
id: doc_1
71+
body:
72+
body: [ "ElasticSearch is an open source, distributed, RESTful, search engine which is built on top of Lucene internally and enjoys all the features it provides.", "You Know, for Search!" ]
73+
refresh: true
74+
75+
- match: { result: created }
76+
77+
- do:
78+
search:
79+
index: test-dense-index
80+
body:
81+
query:
82+
match_all: {}
83+
highlight:
84+
fields:
85+
another_body: {}
86+
87+
- match: { hits.total.value: 1 }
88+
- match: { hits.hits.0._id: "doc_1" }
89+
- not_exists: hits.hits.0.highlight.another_body
6190

6291
---
6392
"Highlighting using a sparse embedding model":

0 commit comments

Comments
 (0)