# PutIndexTemplateRequest and custom plugin

**URL:** <https://discuss.elastic.co/t/putindextemplaterequest-and-custom-plugin/373991>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [February 3, 2025, 1:23am UTC](https://discuss.elastic.co/t/putindextemplaterequest-and-custom-plugin/373991 "2025-02-03T01:23:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![antoinelefloch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/antoinelefloch/32/24577_2.png) [@antoinelefloch](https://discuss.elastic.co/u/antoinelefloch)\
**Post date:** [February 3, 2025, 1:23am UTC](https://discuss.elastic.co/t/putindextemplaterequest-and-custom-plugin/373991/1 "2025-02-03T01:23:41Z")

</div>

Hello,  
About the Java client, I have the same problem as

> <https://github.com/elastic/elasticsearch-java/issues/299>
>
> \### Java API client version
> 
> 8.2
> 
> \### Java version
> 
> 12
> 
> \### Elasticsearch Versio…n
> 
> 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

when I try to use the similarity that I defined in my plugin.

I can create the index template using PUT with curl.  
But I have the same exception as #299 if I try to use the java client.  
I have Elastic and co.elastic.clients version 8.17.0.

If I do

```auto
"similarity": {
        "my_similarity": {
          "type": "my_similarity_type"
        }

```

where `my_similarity_type` is defined in my plugin, it works with curl, but I get the same exception when I use the client with the same code as #299

```auto
co.elastic.clients.json.JsonpMappingException: Error deserializing co.elastic.clients.elasticsearch.indices.SettingsSimilarity: Unknown 'type' value: 'my_similarity_type' (JSON path: settings.similarity.nemo) (in object at line no=9, column no=18, offset=232)

```

note: everything works when I don't use my plugin and when I do

```auto
"similarity" : {
                "my_bm25" : {
                  "type" : "BM25",
                  "b" : "0.0",
                  "k1" : "0.0"
                }
              }

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 3, 2025, 9:02am UTC](https://discuss.elastic.co/t/putindextemplaterequest-and-custom-plugin/373991/2 "2025-02-03T09:02:14Z")

</div>

Bonjour Antoine 😉

Could you share the full stack trace please?  
Also your java code would help.

May be there's a way to provide the type using something like `Kind("my_similarity_type")` but I'm unsure. @ltrotta would be able to tell more.

Worse case, you can fallback to the low level client to solve the immediate problem.

---

<div class="post-metadata">

**Author:** ![ltrotta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ltrotta/32/124003_2.png) [@ltrotta](https://discuss.elastic.co/u/ltrotta)\
**Post date:** [February 3, 2025, 9:29am UTC](https://discuss.elastic.co/t/putindextemplaterequest-and-custom-plugin/373991/3 "2025-02-03T09:29:58Z")

</div>

Hello!  
I have to investigate a bit more because I was pretty sure the problem was already solved, but it seems like the solution was reversed at some point. I'll get back ASAP.

---

<div class="post-metadata">

**Author:** ![antoinelefloch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/antoinelefloch/32/24577_2.png) [@antoinelefloch](https://discuss.elastic.co/u/antoinelefloch)\
**Post date:** [February 3, 2025, 11:13am UTC](https://discuss.elastic.co/t/putindextemplaterequest-and-custom-plugin/373991/4 "2025-02-03T11:13:57Z")

</div>

> [@antoinelefloch](#):
>
> #299

actually, #299 is fixed, but the similar problem I have, is when the similarity type comes from a plugin. To me, it is another ticket.

As for the Java and the trace, here is what I have:

elastic-simple.json

```auto
{
  "index_patterns": [
    "test_similarity"
  ],
  "template": {
    "settings": {
      "index": {
        "similarity": {
          "my_similarity": {
            "type": "nemo-custom"
          }
        }
      }
    }
  }
}

```

elastic-simple-bm25.json

```auto
{
  "index_patterns": [
    "test_similarity"
  ],
  "template": {
    "settings": {
      "index": {
        "similarity": {
          "my_bm25": {
            "type": "BM25",
            "b": 0.0,
            "k1": 0.0,
            "discount_overlaps": true
          }
        }
      }
    }
  }
}

```

Here is what I use to reproduce the problem with Elastic 8.17.0 in a container. It works with elastic-simple-bm25.json but doesn't with elastic-simple.json:

```auto
        private void discussElasticSimple() {
            String jsonString;
            try {
                jsonString = EsYesUtils.readResource("elastic-simple.json");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

            InputStream stream = new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8));
            PutIndexTemplateRequest putIndexTemplateRequest = new PutIndexTemplateRequest.Builder()
                    .name("my-template")
                    .create(true)
                    .withJson(stream)
                    .build();

            System.out.println("template = " + putIndexTemplateRequest.template());
}

```

Here is the trace:

```auto
Caused by: co.elastic.clients.json.JsonpMappingException: Error deserializing co.elastic.clients.elasticsearch.indices.SettingsSimilarity: Unknown 'type' value: 'nemo-custom' (JSON path: template.settings.index.similarity.my_similarity) (in object at line no=9, column no=29, offset=154)
	at co.elastic.clients.json.ObjectDeserializer.lambda$setTypeProperty$0(ObjectDeserializer.java:359)
	at co.elastic.clients.json.ObjectDeserializer.parseUnknownField(ObjectDeserializer.java:284)
	at co.elastic.clients.json.ObjectDeserializer.deserializeInner(ObjectDeserializer.java:229)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:166)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:157)
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:77)
	at co.elastic.clients.json.BuildFunctionDeserializer.deserialize(BuildFunctionDeserializer.java:47)
	at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43)
	at co.elastic.clients.json.JsonpDeserializerBase$StringMapDeserializer.deserialize(JsonpDeserializerBase.java:349)
	at co.elastic.clients.json.JsonpDeserializerBase$StringMapDeserializer.deserialize(JsonpDeserializerBase.java:333)
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:77)
	at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:78)
	at co.elastic.clients.json.ObjectDeserializer.deserializeInner(ObjectDeserializer.java:214)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:166)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:157)
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:77)
	at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:79)
	at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43)
	at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:78)
	at co.elastic.clients.json.ObjectDeserializer.deserializeInner(ObjectDeserializer.java:214)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:166)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:157)
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:77)
	at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:79)
	at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43)
	at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:78)
	at co.elastic.clients.json.ObjectDeserializer.deserializeInner(ObjectDeserializer.java:214)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:166)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:157)
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:77)
	at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:79)
	at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43)
	at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:78)
	at co.elastic.clients.json.ObjectDeserializer.deserializeInner(ObjectDeserializer.java:214)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:166)
	at co.elastic.clients.util.WithJsonObjectBuilderBase.withJson(WithJsonObjectBuilderBase.java:54)
	at co.elastic.clients.json.WithJson.withJson(WithJson.java:43)

```

It works when I use curl:

```auto
curl -X PUT -H 'Content-Type: application/json' -u elastic:s3cret! -k -d @/Users/lef/dev/esyes-configuration/src/test/resources/elastic-simple.json http://127.0.0.1:33043/_index_template/search-index-template

```

---

<div class="post-metadata">

**Author:** ![ltrotta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ltrotta/32/124003_2.png) [@ltrotta](https://discuss.elastic.co/u/ltrotta)\
**Post date:** [February 4, 2025, 5:27pm UTC](https://discuss.elastic.co/t/putindextemplaterequest-and-custom-plugin/373991/5 "2025-02-04T17:27:29Z")

</div>

Hello! I can confirm that this is the exact same issue, which was fixed and accidentally reversed shortly after 😅 a new fix is ready and it will be merged shortly, hopefully permanently this time. It should be part of the next patch, so 8.17.2 🙂

---

<div class="post-metadata">

**Author:** ![antoinelefloch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/antoinelefloch/32/24577_2.png) [@antoinelefloch](https://discuss.elastic.co/u/antoinelefloch)\
**Post date:** [February 5, 2025, 2:39pm UTC](https://discuss.elastic.co/t/putindextemplaterequest-and-custom-plugin/373991/6 "2025-02-05T14:39:46Z")

</div>

OK thank you,  
Is it related to [elasticsearch-specification](https://github.com/elastic/elasticsearch-specification) again ?  
When was the regression introduced ? Could I test with a former version ?

---

<div class="post-metadata">

**Author:** ![ltrotta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ltrotta/32/124003_2.png) [@ltrotta](https://discuss.elastic.co/u/ltrotta)\
**Post date:** [February 5, 2025, 4:27pm UTC](https://discuss.elastic.co/t/putindextemplaterequest-and-custom-plugin/373991/7 "2025-02-05T16:27:15Z")

</div>

Unfortunately the fix was never released, because of bad timing: it should've been out with 8.13.0, but then the regression was introduced just before the final build. And yes it's still the common[elasticsearch-specification](https://github.com/elastic/elasticsearch-specification), all clients are generated from it. 8.17.2 should be out around next week, if it takes longer then I'll point you to a snapshot version of it that you will be able to test.

---

<div class="post-metadata">

**Author:** ![antoinelefloch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/antoinelefloch/32/24577_2.png) [@antoinelefloch](https://discuss.elastic.co/u/antoinelefloch)\
**Post date:** [February 12, 2025, 5:12pm UTC](https://discuss.elastic.co/t/putindextemplaterequest-and-custom-plugin/373991/8 "2025-02-12T17:12:44Z")

</div>

Hello,  
I confirm that 8.17.2 of the java client solves the problem,  
thank you
