Closed
Description
Java API client version
8.2
Java version
12
Elasticsearch Version
8.2
Problem description
Hello,
Using the following index template:
PUT /_index_template/test_bm25
{
"index_patterns" : ["test_bm25*"],
"template" : {
"settings": {
"index" : {
"similarity": {
"my_bm25": {
"type": "BM25",
"b": 0.0,
"k1": 0.0
}
}
}
}
}
}
# PUT /_index_template/test_bm25
{
"acknowledged" : true
}
GET /_index_template/test_bm25
# GET /_index_template/test_bm25
{
"index_templates" : [
{
"name" : "test_bm25",
"index_template" : {
"index_patterns" : [
"test_bm25*"
],
"template" : {
"settings" : {
"index" : {
"similarity" : {
"my_bm25" : {
"type" : "BM25",
"b" : "0.0",
"k1" : "0.0"
}
}
}
}
},
"composed_of" : [ ]
}
}
]
}
The java client fails to parse as it looks like the json parser rules are not correct when defning a custom similarity.
Also tried to load it using withJson() with the same result (which makes sense).
See code below:
import java.io.FileInputStream;
import java.io.Reader;
import java.io.StringReader;
import co.elastic.clients.elasticsearch.indices.PutIndexTemplateRequest;
import co.elastic.clients.elasticsearch.indices.SettingsSimilarity;
import co.elastic.clients.elasticsearch.indices.SettingsSimilarityBm25;
public class ESClientTester {
public static void main(String[] args) {
try {
PutIndexTemplateRequest req1 = new PutIndexTemplateRequest.Builder()
.name("test_bm25")
.indexPatterns("test_bm25")
.template(template -> template
.settings(settings -> settings
.index(index -> index
.similarity(similarity -> similarity
// no custom name here allowed ?
.bm25(bm25 -> bm25
.b(0) // type error: float value shall be allowed
.k1(0.0)
)
)
)
)
)
.build();
Reader queryJson = new StringReader(
"{" +
"\"index_patterns\" : [\"test_bm25\"]," +
"\"template\" : {" +
"\"settings\": {" +
"\"index\" : {" +
"\"similarity\": {" +
"\"my_bm25\": {" +
"\"type\": \"BM25\"," +
"\"b\": 0.0," +
"\"k1\": 0.0," +
"\"discount_overlaps\": true" +
"}" +
"}" +
"}" +
"}" +
"}" +
"}"
);
PutIndexTemplateRequest req2 = new PutIndexTemplateRequest.Builder()
.name("test_bm25")
.withJson(queryJson)
.build();
System.out.println("ok");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Exception: co.elastic.clients.json.JsonpMappingException: Error deserializing co.elastic.clients.elasticsearch.indices.SettingsSimilarity: Unknown field 'my_bm25' (JSON path: template.settings.index.similarity.my_bm25) (line no=1, column no=97, offset=96)
Best regards,
Alexis Berger