elasticsearch-java icon indicating copy to clipboard operation
elasticsearch-java copied to clipboard

Error deserializing co.elastic.clients.elasticsearch._types.analysis.Analyzer: Property 'type' not found

Open pasupathi-rajamanickam-odp opened this issue 3 years ago • 3 comments

Java API client version

8.4.0

Java version

JDK-17

Elasticsearch Version

7.17.2

Problem description

Trying to read settings for an index, throwing Error deserializing co.elastic.clients.elasticsearch._types.analysis.Analyzer: Property 'type' not found Exception


var indexSetting = new GetIndicesSettingsRequest.Builder().index("index_1000").build();

try {
    var settings = elasticSearchClientConfig.getElasticsearchIndicesClient().getSettings(indexSetting);
    System.out.println(settings);
} catch(Exception e) {
    e.printStackTrace();
}

Settings

{
    "index_1000": {
        "settings": {
            "index": {
                "analysis": {
                    "analyzer": {
                        "edgengram-analyzer": {
                            "tokenizer": "edge_ngram_tokenizer"
                        }
                    }
                }
            }
        }
    }
}

Exception trace

Error deserializing co.elastic.clients.elasticsearch._types.analysis.Analyzer: Property 'type' not found (JSON path: index_1000.settings.index.analysis.analyzer['edgengram-analyzer']) (line no=1, column no=56407, offset=-1)

@swallez Please help fixing this.

We've seen this as well in testing.

marcreichman avatar Sep 02 '22 14:09 marcreichman

This also happens for me with library versions 7.17.6 and 8.4.1 with the Get Index API, à la

client.indices().get(builder -> builder.index("*"))

It's a show-stopper for migrating to the Java Client, away from the RestHighLevelClient!

bpenrod avatar Sep 16 '22 22:09 bpenrod

We're hitting this too in trying to migrate

rockwotj avatar Oct 25 '22 05:10 rockwotj

FYI I'm able to workaround this via the following (kotlin):

val unwrapped = DelegatingDeserializer.unwrap(Analyzer._DESERIALIZER) as ObjectDeserializer<*>
unwrapped.setTypeProperty("type", "custom")

EDIT: simpler

rockwotj avatar Oct 26 '22 02:10 rockwotj

FYI I'm able to workaround this via the following (kotlin):

            Analyzer._DESERIALIZER
                .let { DelegatingDeserializer.unwrap(it) }
                .let { DelegatingDeserializer.unwrap(it) }
                .let { unwrapped ->
                    unwrapped as ObjectDeserializer<*>
                    unwrapped.setTypeProperty("type", "custom")
                }

Don't know how to port this to Java, still looking...

Work around Java version, thanks a ton @rockwotj

ObjectDeserializer unwrapped = (ObjectDeserializer) DelegatingDeserializer.unwrap(Analyzer._DESERIALIZER );
unwrapped.setTypeProperty("type", "custom");

or just add "type": "custom", to json. even if it is default value, i really needs.

{
    "index_1000": {
        "settings": {
            "index": {
                "analysis": {
                    "analyzer": {
                        "edgengram-analyzer": {
                            "type": "custom",
                            "tokenizer": "edge_ngram_tokenizer"
                        }
                    }
                }
            }
        }
    }
}

skyer9 avatar Dec 28 '22 06:12 skyer9