Skip to content

Commit 23a1719

Browse files
committed
Fix NPE in SemanticTextHighlighter
If the model settings is null then the field is guaranteed to not have any indexed content. Closes #129501
1 parent 94c63ca commit 23a1719

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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 index":
87+
- do:
88+
search:
89+
index: test-sparse-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:

0 commit comments

Comments
 (0)