ElasticsearchIndicesClient#getMapping(GetMappingRequest) throws on reading response when mapping contains an object property
See original GitHub issueUsing version 7.15.2.
When an index mapping contains a property that is an object,
co.elastic.clients.elasticsearch.indices.ElasticsearchIndicesClient#getMapping(co.elastic.clients.elasticsearch.indices.GetMappingRequest)
crashes on parsing the result.
This can be tested with the following code:
class Name {
String first;
String last;
public Name(String first, String last) {
this.first = first;
this.last = last;
}
// getter+setter
}
class Person {
String id;
Name name;
public Person(String id, Name name) {
this.id = id;
this.name = name;
}
// getter+setter
}
ElasticsearchClient client = ... // setup the ElasticsearchClient
String index = "testindex";
Person person = new Person("42", new Name("Ford", "Prefect"));
client.index(b -> b.index(index).id(person.id).document(person));
GetMappingResponse getMappingResponse = client.indices().getMapping(mrb -> mrb.index(index));
This will produce the following error:
jakarta.json.stream.JsonParsingException: Property 'type' not found
at co.elastic.clients.json.JsonpUtils.lookAheadFieldValue(JsonpUtils.java:139)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:128)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:95)
at co.elastic.clients.json.BuildFunctionDeserializer.deserialize(BuildFunctionDeserializer.java:42)
at co.elastic.clients.json.JsonpDeserializer$LazyDeserializer.deserialize(JsonpDeserializer.java:205)
at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:102)
at co.elastic.clients.json.JsonpDeserializer$StringMapDeserializer.deserialize(JsonpDeserializer.java:461)
at co.elastic.clients.json.JsonpDeserializer$StringMapDeserializer.deserialize(JsonpDeserializer.java:447)
at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:102)
at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:68)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:122)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:95)
at co.elastic.clients.json.BuildFunctionDeserializer.deserialize(BuildFunctionDeserializer.java:42)
at co.elastic.clients.json.JsonpDeserializer$LazyDeserializer.deserialize(JsonpDeserializer.java:205)
at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:102)
at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:68)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:122)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:95)
at co.elastic.clients.json.BuildFunctionDeserializer.deserialize(BuildFunctionDeserializer.java:42)
at co.elastic.clients.json.JsonpDeserializer$LazyDeserializer.deserialize(JsonpDeserializer.java:205)
at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:102)
at co.elastic.clients.base.DictionaryResponse.lambda$setupDictionaryResponseDeserializer$0(DictionaryResponse.java:148)
at co.elastic.clients.json.ObjectDeserializer.parseUnknownField(ObjectDeserializer.java:150)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:120)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:95)
at co.elastic.clients.json.BuildFunctionDeserializer.deserialize(BuildFunctionDeserializer.java:42)
at co.elastic.clients.json.JsonpDeserializer$LazyDeserializer.deserialize(JsonpDeserializer.java:205)
at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:102)
at co.elastic.clients.base.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:242)
at co.elastic.clients.base.rest_client.RestClientTransport.performRequest(RestClientTransport.java:104)
at co.elastic.clients.elasticsearch.indices.ElasticsearchIndicesClient.getMapping(ElasticsearchIndicesClient.java:1044)
at co.elastic.clients.elasticsearch.indices.ElasticsearchIndicesClient.getMapping(ElasticsearchIndicesClient.java:1061)
The mapping returned from the server:
{
"testindex" : {
"mappings" : {
"properties" : {
"id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"name" : {
"properties" : {
"first" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"last" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
}
I debugged through the code; when reading the properties, the parser comes to the name
entry and then on finding a START_OBJECT tries to get the type
property of the object, basically expecting something like
{
"type": "object", <=== Elasticsearch does not send a type entry here
"properties": {
"first": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"last": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
Even when the mapping is stored explicitly in Elasticsearch with the type object, it is not returned on getting the mapping.
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (9 by maintainers)
Top Results From Across the Web
How to get mapping for an index in elasticsearch nest?
With NEST, the JSON response is deserialized into a .NET type to work with, in this case, GetMappingResponse .
Read more >Elasticsearch Mapping Basics & Examples (After Create Index)
Within a search engine, mapping defines how a document is indexed and how it indexes and stores its fields. We can compare mapping...
Read more >Get Mappings API | Java REST Client [7.17] - Elastic
getMapping(request, requestOptions);. Synchronous calls may throw an IOException in case of either failing to parse the REST response in the high-level REST ...
Read more >Get the mapping of an Elasticsearch index in Python
Make sure you already have an index created (with a mapping ... schema (as a Python dict object) in order to parse its...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @swallez , i still get this exception in 7.17.0 with the following mapping:
The stacktrace reads like:
Should I open a new bug report for this one or could this be addressed here?
Thanks for your help.
@LordOfTheHelmet please open a new issue as this is a different issue from this one. Thanks!