From 91f4d1ffc515a09ddea9bee687f6231e1cf8405e Mon Sep 17 00:00:00 2001 From: zhichao-aws Date: Wed, 20 Sep 2023 17:13:10 +0800 Subject: [PATCH] add it Signed-off-by: zhichao-aws --- .../neuralsearch/query/SparseEncodingQueryIT.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/org/opensearch/neuralsearch/query/SparseEncodingQueryIT.java b/src/test/java/org/opensearch/neuralsearch/query/SparseEncodingQueryIT.java index 27517ddcb..7d2a2314c 100644 --- a/src/test/java/org/opensearch/neuralsearch/query/SparseEncodingQueryIT.java +++ b/src/test/java/org/opensearch/neuralsearch/query/SparseEncodingQueryIT.java @@ -14,6 +14,7 @@ import org.junit.After; import org.junit.Before; +import org.opensearch.client.ResponseException; import org.opensearch.index.query.BoolQueryBuilder; import org.opensearch.index.query.MatchAllQueryBuilder; import org.opensearch.index.query.MatchQueryBuilder; @@ -263,6 +264,18 @@ public void testBooleanQuery_withSparseEncodingAndBM25Queries() { assertTrue(minExpectedScore < objectToFloat(firstInnerHit.get("_score"))); } + @SneakyThrows + public void testBasicQueryUsingQueryText_whenQueryWrongFieldType_thenFail() { + initializeIndexIfNotExist(TEST_TEXT_AND_SPARSE_ENCODING_FIELD_INDEX_NAME); + String modelId = getDeployedModelId(); + + SparseEncodingQueryBuilder sparseEncodingQueryBuilder = new SparseEncodingQueryBuilder().fieldName(TEST_TEXT_FIELD_NAME_1) + .queryText(TEST_QUERY_TEXT) + .modelId(modelId); + + expectThrows(ResponseException.class, () -> search(TEST_TEXT_AND_SPARSE_ENCODING_FIELD_INDEX_NAME, sparseEncodingQueryBuilder, 1)); + } + @SneakyThrows protected void initializeIndexIfNotExist(String indexName) { if (TEST_BASIC_INDEX_NAME.equals(indexName) && !indexExists(indexName)) {