Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing required property 'Term.tokens' in Termvectors response. #184

Closed
jerryguowei opened this issue Mar 4, 2022 · 2 comments · Fixed by #292
Closed

Missing required property 'Term.tokens' in Termvectors response. #184

jerryguowei opened this issue Mar 4, 2022 · 2 comments · Fixed by #292
Labels
Area: Specification Related to the API spec used to generate client code

Comments

@jerryguowei
Copy link

Java API client version

7.17.1

Java version

11

Elasticsearch Version

7.17.1

Problem description

I got an en exception when I run termsVector request.

Exception in thread "main" co.elastic.clients.util.MissingRequiredPropertyException: Missing required property 'Term.tokens'
	at co.elastic.clients.util.ApiTypeHelper.requireNonNull(ApiTypeHelper.java:76)
	at co.elastic.clients.util.ApiTypeHelper.unmodifiableRequired(ApiTypeHelper.java:141)
	at co.elastic.clients.elasticsearch.core.termvectors.Term.<init>(Term.java:72)
	at co.elastic.clients.elasticsearch.core.termvectors.Term.<init>(Term.java:51)
	at co.elastic.clients.elasticsearch.core.termvectors.Term$Builder.build(Term.java:251)
	at co.elastic.clients.elasticsearch.core.termvectors.Term$Builder.build(Term.java:167)
	at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:80)
	at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43)
	at co.elastic.clients.json.JsonpDeserializerBase$StringMapDeserializer.deserialize(JsonpDeserializerBase.java:346)
	at co.elastic.clients.json.JsonpDeserializerBase$StringMapDeserializer.deserialize(JsonpDeserializerBase.java:332)
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75)
	at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:72)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:176)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:137)
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75)
	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.JsonpDeserializerBase$StringMapDeserializer.deserialize(JsonpDeserializerBase.java:346)
	at co.elastic.clients.json.JsonpDeserializerBase$StringMapDeserializer.deserialize(JsonpDeserializerBase.java:332)
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75)
	at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:72)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:176)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:137)
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75)
	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.transport.rest_client.RestClientTransport.decodeResponse(RestClientTransport.java:328)
	at co.elastic.clients.transport.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:294)
	at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:147)
	at co.elastic.clients.elasticsearch.ElasticsearchClient.termvectors(ElasticsearchClient.java:1647)
	at co.elastic.clients.elasticsearch.ElasticsearchClient.termvectors(ElasticsearchClient.java:1665)
	at com.duduanan.TestTermvectors.main(TestTermvectors.java:33)

The token actually is not mandatory, but the client treat it as a mandatory field.

Steps to reproduce the issue:

  1. start docker:

docker run -t -p 9200:9200 -e "discovery.type=single-node" -e "xpack.security.enabled=false" -e \ "path.repo=/tmp" docker.elastic.co/elasticsearch/elasticsearch:7.17.1

  1. run java code.
public class TestTermvectors
{
   public static void main(String[] args) throws IOException
   {
       ElasticsearchClient client = null;
       try
       {
           client = buildClient();

           client.indices().create(c -> c.index("my-index-1")
                                         .mappings(m -> m.properties("test_field", p -> p.text(text -> text.termVector(TermVectorOption.Yes)))
                                         )
           );
           Map<String, String> doc = Map.of("test_field", "test test test test");
           client.termvectors(tv -> tv.index("my-index-1").doc(doc).payloads(false).positions(false).offsets(false));
       }
       finally
       {
           if (client != null)
           {
               client._transport().close();
           }
       }
   }

   public static ElasticsearchClient buildClient()
   {
       RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build();
       ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
       return new ElasticsearchClient(transport);
   }
}
@jerryguowei
Copy link
Author

This is an error in the api specification. Is there any plan to fix this bug?

@swallez
Copy link
Member

swallez commented May 24, 2022

This has been fixed in PR #292, backported to version 8.2 in PR #293 and to version 7.17 in PR #294.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Specification Related to the API spec used to generate client code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants