# InferenceConfig doesn't support text\_expansion value when creating a pipeline from java

**URL:** <https://discuss.elastic.co/t/inferenceconfig-doesnt-support-text-expansion-value-when-creating-a-pipeline-from-java/342377>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [September 5, 2023, 9:05pm UTC](https://discuss.elastic.co/t/inferenceconfig-doesnt-support-text-expansion-value-when-creating-a-pipeline-from-java/342377 "2023-09-05T21:05:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajperez](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@ajperez](https://discuss.elastic.co/u/ajperez)\
**Post date:** [September 5, 2023, 9:05pm UTC](https://discuss.elastic.co/t/inferenceconfig-doesnt-support-text-expansion-value-when-creating-a-pipeline-from-java/342377/1 "2023-09-05T21:05:17Z")

</div>

When creating a PutPipelineRequest with the Java client version 8.9.1, InferenceConfig doesn’t support “_text\_expansion_” value, an error is thrown `co.elastic.clients.json.JsonpMappingException: Error deserializing co.elastic.clients.elasticsearch.ingest.InferenceConfig: Unknown field 'text_expansion' (JSON path: processors[0].inference.inference_config.text_expansion)`  
If the pipeline is created with Elastic Api following the steps from the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/8.9/semantic-search-elser.html#inference-ingest-pipeline) there is no error 🙂. Maybe this is a bug in the java client, and it hasn't been updated yet.  
Here is the code I used to create the pipeline programmatically in java:

```auto
InputStream input = new ClassPathResource("elser_pipeline_config.json").getInputStream();

PutPipelineRequest request = PutPipelineRequest.of(pl->pl
                    .id("my_pipeline_test")
                    .withJson(input)
            );
elasticsearchClient.ingest().putPipeline(request);

// elser_pipeline_config.json :
{
  "description":"My test elser pipeline",
  "processors": [
    {
      "inference": {
        "model_id": ".elser_model_1",
        "target_field": "ml",
        "field_map": { 
          "text": "text_field"
        },
        "inference_config": {
          "text_expansion": { 
            "results_field": "tokens"
          }
        }
      }
    }
  ]
}

```

What can I do to create the pipeline from Java?  
If I create it with the Low Level Client I'll have to have two active clients (Low and High level clients), that would not be optimal.  
Thank you.

---

<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:** [September 6, 2023, 5:27am UTC](https://discuss.elastic.co/t/inferenceconfig-doesnt-support-text-expansion-value-when-creating-a-pipeline-from-java/342377/2 "2023-09-06T05:27:14Z")

</div>

> [@ajperez](#):
>
> If I create it with the Low Level Client I'll have to have two active clients (Low and High level clients), that would not be optimal.

I'm not answering on the main question but I guess @swallez will do. 😊

To create the "rich" Java Client, you need to create a Low Level one. So there's no overhead by calling the low level instance instead.

---

<div class="post-metadata">

**Author:** ![ajperez](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@ajperez](https://discuss.elastic.co/u/ajperez)\
**Post date:** [September 6, 2023, 1:13pm UTC](https://discuss.elastic.co/t/inferenceconfig-doesnt-support-text-expansion-value-when-creating-a-pipeline-from-java/342377/3 "2023-09-06T13:13:07Z")

</div>

I hope @swallez have a way to address the error. It's better to make it work with the high level java client to avoid deserialization work and object creation.  
InferenceConfig currently only supports classification and regression types.

---

<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:** [September 6, 2023, 1:27pm UTC](https://discuss.elastic.co/t/inferenceconfig-doesnt-support-text-expansion-value-when-creating-a-pipeline-from-java/342377/4 "2023-09-06T13:27:57Z")

</div>

Just to make sure. We don't say [high level java client](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-getting-started.html) for the new [Java API Client](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/introduction.html) 😉

May be open an issue at [GitHub - elastic/elasticsearch-java: Official Elasticsearch Java Client](https://github.com/elastic/elasticsearch-java/)?

---

<div class="post-metadata">

**Author:** ![ajperez](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@ajperez](https://discuss.elastic.co/u/ajperez)\
**Post date:** [September 6, 2023, 8:43pm UTC](https://discuss.elastic.co/t/inferenceconfig-doesnt-support-text-expansion-value-when-creating-a-pipeline-from-java/342377/5 "2023-09-06T20:43:13Z")

</div>

I'm posting my temporal solution as this can take a while to get fixed.  
Taking the suggestion that @dadoonet gave me, I'm using the same RestClient instance needed to create the ElasticsearchClient to perform the Rest request.  
Step1: Create the RestClient as specified in the [documentation](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/getting-started-java.html#_connecting).  
Step2: Create the Request and set in its body the pipeline settings.

```auto
public boolean createUpdatePipeline(){
Request request = new Request("PUT", "/_ingest/pipeline/my_test_pipeline");
String elserPipeline = 
"{\n" +
            " \"processors\": [\n" +
            " {\n" +
            " \"inference\": {\n" +
            " \"model_id\": \".elser_model_1\",\n" +
            " \"target_field\": \"ml\",\n" +
            " \"field_map\": { \n" +
            " \"text\": \"text_field\"\n" +
            " },\n" +
            " \"inference_config\": {\n" +
            " \"text_expansion\": { \n" +
            " \"results_field\": \"tokens\"\n" +
            " }\n" +
            " }\n" +
            " }\n" +
            " }\n" +
            " ]\n" +
            "}";
request.setJsonEntity(elserPipeline);
Response response = elasticRestClient.performRequest(request); // elasticRestClient is from step1.
if(response.getStatusLine().getStatusCode() == 200){
                ObjectMapper objectMapper = new ObjectMapper();
                String acknowledged = EntityUtils.toString(response.getEntity());
                AcknowledgedResponse ak_response = objectMapper.readValue(acknowledged, CreatePipelineResponse.class);
                return ak_response.acknowledged(); // create the CreatePipelineResponse class implementing the AcknowledgedResponse interface from Elastic, that way when the error is fixed it won't require many code changes.
            } else return false;
}

```

I posted this solution in case someone else runs into the same problem as I did.  
Do I need to create a new bug so this error can be seen by the Elasticsearch/java team?

---

<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:** [September 6, 2023, 9:05pm UTC](https://discuss.elastic.co/t/inferenceconfig-doesnt-support-text-expansion-value-when-creating-a-pipeline-from-java/342377/6 "2023-09-06T21:05:35Z")

</div>

Thanks for sharing your solution.

Indeed, it'd be great to write all that in a new issue with the workaround. Thanks!

---

<div class="post-metadata">

**Author:** ![ajperez](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@ajperez](https://discuss.elastic.co/u/ajperez)\
**Post date:** [September 19, 2023, 9:04pm UTC](https://discuss.elastic.co/t/inferenceconfig-doesnt-support-text-expansion-value-when-creating-a-pipeline-from-java/342377/7 "2023-09-19T21:04:33Z")

</div>

I created the [issue](https://github.com/elastic/elasticsearch-java/issues/667) with the workaround solution. It should be noted that making a [text\_expansion](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-text-expansion-query.html#query-dsl-text-expansion-query) query is not supported by the Java API Client yet, version 8.10.1.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 17, 2023, 9:04pm UTC](https://discuss.elastic.co/t/inferenceconfig-doesnt-support-text-expansion-value-when-creating-a-pipeline-from-java/342377/8 "2023-10-17T21:04:58Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
