diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/script/KNNVectorScoreScript.java b/src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/script/KNNVectorScoreScript.java index 18371f4d..b3801114 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/script/KNNVectorScoreScript.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/script/KNNVectorScoreScript.java @@ -129,9 +129,9 @@ private void validateAndInitParams(Map params) { } // validate space - final Object space = params.get("space"); + final Object space = params.get("space_type"); if (space == null) { - throw new IllegalArgumentException("Missing parameter [space]"); + throw new IllegalArgumentException("Missing parameter [space_type]"); } this.similaritySpace = (String)space; if (!KNNConstants.COSINESIMIL.equalsIgnoreCase(similaritySpace) && !KNNConstants.L2.equalsIgnoreCase(similaritySpace)) { diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/scripts/KNNScriptScoringIT.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/scripts/KNNScriptScoringIT.java index 5492dd5c..3f3f14a8 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/scripts/KNNScriptScoringIT.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/scripts/KNNScriptScoringIT.java @@ -60,7 +60,7 @@ public void testKNNL2ScriptScore() throws Exception { float[] queryVector = {1.0f, 1.0f}; params.put("field", FIELD_NAME); params.put("vector", queryVector); - params.put("space", KNNConstants.L2); + params.put("space_type", KNNConstants.L2); Request request = constructKNNScriptQueryRequest(INDEX_NAME, qb, params, queryVector); Response response = client().performRequest(request); assertEquals(request.getEndpoint() + ": failed", RestStatus.OK, @@ -106,7 +106,7 @@ public void testKNNCosineScriptScore() throws Exception { * params": { * "field": "my_dense_vector", * "vector": [2.0, 2.0], - * "space": "L2" + * "space_type": "L2" * } * * @@ -114,7 +114,7 @@ public void testKNNCosineScriptScore() throws Exception { float[] queryVector = {2.0f, -2.0f}; params.put("field", FIELD_NAME); params.put("vector", queryVector); - params.put("space", KNNConstants.COSINESIMIL); + params.put("space_type", KNNConstants.COSINESIMIL); Request request = constructKNNScriptQueryRequest(INDEX_NAME, qb, params, queryVector); Response response = client().performRequest(request); assertEquals(request.getEndpoint() + ": failed", RestStatus.OK, @@ -151,13 +151,13 @@ public void testKNNInvalidSourceScript() throws Exception { * params": { * "field": "my_dense_vector", * "vector": [2.0, 2.0], - * "space": "cosinesimil" + * "space_type": "cosinesimil" * } */ float[] queryVector = {2.0f, -2.0f}; params.put("field", FIELD_NAME); params.put("vector", queryVector); - params.put("space", KNNConstants.COSINESIMIL); + params.put("space_type", KNNConstants.COSINESIMIL); Script script = new Script(Script.DEFAULT_SCRIPT_TYPE, KNNScoringScriptEngine.NAME, "Dummy_source", params); ScriptScoreQueryBuilder sc = new ScriptScoreQueryBuilder(qb, script); @@ -196,7 +196,7 @@ public void testInvalidSpace() throws Exception { float[] queryVector = {2.0f, -2.0f}; params.put("field", FIELD_NAME); params.put("vector", queryVector); - params.put("space", INVALID_SPACE); + params.put("space_type", INVALID_SPACE); Request request = constructKNNScriptQueryRequest(INDEX_NAME, qb, params, queryVector); ResponseException ex = expectThrows(ResponseException.class, () -> client().performRequest(request)); assertThat(EntityUtils.toString(ex.getResponse().getEntity()), @@ -216,7 +216,7 @@ public void testMissingParamsInScript() throws Exception { Map params = new HashMap<>(); float[] queryVector = {2.0f, -2.0f}; params.put("vector", queryVector); - params.put("space", KNNConstants.COSINESIMIL); + params.put("space_type", KNNConstants.COSINESIMIL); Request request = constructKNNScriptQueryRequest(INDEX_NAME, qb, params, queryVector); ResponseException ex = expectThrows(ResponseException.class, () -> client().performRequest(request)); assertThat(EntityUtils.toString(ex.getResponse().getEntity()), @@ -232,11 +232,11 @@ public void testMissingParamsInScript() throws Exception { // Remove space parameter params.put("vector", queryVector); - params.remove("space"); + params.remove("space_type"); Request space_request = constructKNNScriptQueryRequest(INDEX_NAME, qb, params, queryVector); ex = expectThrows(ResponseException.class, () -> client().performRequest(space_request)); assertThat(EntityUtils.toString(ex.getResponse().getEntity()), - containsString("Missing parameter [space]")); + containsString("Missing parameter [space_type]")); } public void testUnequalDimensions() throws Exception { @@ -255,7 +255,7 @@ public void testUnequalDimensions() throws Exception { float[] queryVector = {2.0f, -2.0f, -2.0f}; // query dimension and field dimension mismatch params.put("field", FIELD_NAME); params.put("vector", queryVector); - params.put("space", KNNConstants.COSINESIMIL); + params.put("space_type", KNNConstants.COSINESIMIL); Request request = constructKNNScriptQueryRequest(INDEX_NAME, qb, params, queryVector); ResponseException ex = expectThrows(ResponseException.class, () -> client().performRequest(request)); assertThat(EntityUtils.toString(ex.getResponse().getEntity()),