question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ElasticsearchIndicesClient#getMapping(GetMappingRequest) throws on reading response when mapping contains an object property

See original GitHub issue

Using 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:closed
  • Created 2 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
LordOfTheHelmetcommented, Feb 9, 2022

Hi @swallez , i still get this exception in 7.17.0 with the following mapping:

{
   "settings":{
      "index":{
         "number_of_shards":"2",
         "number_of_replicas":"0",
         "analysis":{
            "analyzer":{
               "de_stop":{
                  "filter":[
                     "lowercase",
                     "german_normalization"
                  ],
                  "tokenizer":"standard"
               }
            }
         }
      }
   },
   "mappings":{
      "dynamic":"strict",
      "properties":{
         "title":{
            "type":"keyword"
         }
      }
   }
}

The stacktrace reads like:

Exception in thread "main" jakarta.json.stream.JsonParsingException: Property 'type' not found
	at co.elastic.clients.json.JsonpUtils.lookAheadFieldValue(JsonpUtils.java:135)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:184)
	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.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: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.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.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.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.endpoints.DictionaryResponse.lambda$setupDictionaryResponseDeserializer$0(DictionaryResponse.java:148)
	at co.elastic.clients.json.ObjectDeserializer.parseUnknownField(ObjectDeserializer.java:205)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:174)
	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.indices.ElasticsearchIndicesClient.get(ElasticsearchIndicesClient.java:934)
	at co.elastic.clients.elasticsearch.indices.ElasticsearchIndicesClient.get(ElasticsearchIndicesClient.java:950)

Should I open a new bug report for this one or could this be addressed here?

Thanks for your help.

0reactions
swallezcommented, Feb 11, 2022

@LordOfTheHelmet please open a new issue as this is a different issue from this one. Thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found