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

Property 'type' not found

Open fuchaoqun opened this issue 3 years ago • 2 comments

Java API client version

8.1.1

Java version

17

Elasticsearch Version

7.17.1

Problem description

index json:

{
    "settings": {
        "analysis": {
            "filter": {
                "shingle_filter": {
                    "type": "shingle",
                    "min_shingle_size": 2,
                    "max_shingle_size": 3,
                    "output_unigrams": false
                }
            },
            "analyzer": {
                "shingle_analyzer": {
                    "tokenizer": "standard",
                    "filter": [
                        "shingle_filter"
                    ]
                }
            }
        }
    },
    "mappings": {
        "dynamic": "strict",
        "properties": {
            "id": {
                "type": "long"
            },
            "body": {
                "type": "text",
                "fields": {
                    "shingles": {
                        "type": "text",
                        "analyzer": "shingle_analyzer"
                    }
                }
            }
        }
    }
}
CreateIndexRequest createIndexRequest = CreateIndexRequest.of(b -> b
    .index(indexName)
    .withJson(new StringReader(jsonString))
);
jakarta.json.stream.JsonParsingException: Property 'type' not found
	at co.elastic.clients.json.JsonpUtils.lookAheadFieldValue(JsonpUtils.java:170) ~[elasticsearch-java-8.1.1.jar:na]
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:184) ~[elasticsearch-java-8.1.1.jar:na]
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:137) ~[elasticsearch-java-8.1.1.jar:na]
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75) ~[elasticsearch-java-8.1.1.jar:na]
	at co.elastic.clients.json.BuildFunctionDeserializer.deserialize(BuildFunctionDeserializer.java:47) ~[elasticsearch-java-8.1.1.jar:na]
	at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43) ~[elasticsearch-java-8.1.1.jar:na]
	at co.elastic.clients.json.JsonpDeserializerBase$StringMapDeserializer.deserialize(JsonpDeserializerBase.java:346) ~[elasticsearch-java-8.1.1.jar:na]
	at co.elastic.clients.json.JsonpDeserializerBase$StringMapDeserializer.deserialize(JsonpDeserializerBase.java:332) ~[elasticsearch-java-8.1.1.jar:na]

see: https://www.elastic.co/guide/en/elasticsearch/reference/master/analysis-custom-analyzer.html

  • For custom analyzers, use a type of custom or omit the type parameter.

add "type": "custom" can fix the problem, but the document shows it can be omitted

fuchaoqun avatar Mar 25 '22 10:03 fuchaoqun

Thanks for reporting this. It's an issue in the API specification used to produce the Java code.

https://github.com/elastic/elasticsearch-specification/pull/1589 has been opened to solve this issue, and the Java client will be updated once it's fixed.

swallez avatar Mar 29 '22 12:03 swallez

FYI, this does not appear to have been fixed by the changes in the API spec. It still throws

Exception in thread "main" co.elastic.clients.json.JsonpMappingException: Error deserializing co.elastic.clients.elasticsearch._types.analysis.Analyzer: Property 'type' not found (JSON path: settings.analysis.analyzer.shingle_analyzer) (line no=13, column no=38, offset=368)

with Java Client version 8.4.1

Issues #392 and #361 look like they are this same unresolved issue

bpenrod avatar Sep 16 '22 22:09 bpenrod

Closing this as it was fixed in most recent versions of the client. Thanks for the report!

l-trotta avatar Feb 01 '24 15:02 l-trotta