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

java.lang.ClassCastException when "properties" set to [] #5887

Closed
edast opened this issue Apr 20, 2014 · 4 comments · Fixed by #6006
Closed

java.lang.ClassCastException when "properties" set to [] #5887

edast opened this issue Apr 20, 2014 · 4 comments · Fixed by #6006

Comments

@edast
Copy link

edast commented Apr 20, 2014

Some languages (e.g. PHP) don't have Map type just Array, so if "properties" or "fields" in mapping are empty - encoding it to json will result in array [], and not object {}
until 0.9 this was not an issue, but now elasticsearch refuses to create mapping with exception:

Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Map
  at org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parse(ObjectMapper.java:216)
  at org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parseProperties(ObjectMapper.java:258)
  at org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parse(ObjectMapper.java:216)

sample mapping:

curl -XPUT 'localhost:9200/test' -d '{
    "mappings": {
        "test": {
            "_source": {
                "enabled": true
            },
            "properties": {
                "notes": {
                    "index": "no",
                    "type": "nested",
                    "include_in_all": true,
                    "enabled": true,
                    "properties": []
                }
            }
        }
    },
    "settings": {
        "number_of_shards": 1,
        "number_of_replicas": 0
    }
}'

this issue could be resolved by adding addition check to see if fieldNode is instance of Map:

-    } else if (fieldName.equals("properties")) {
+    } else if (fieldName.equals("properties") && fieldNode instanceof Map) {
@evillemez
Copy link

Yeah, this affected me as well, took a bit of time to track down to the root cause.

@kimchy
Copy link
Member

kimchy commented May 1, 2014

Aye, it should be fixed. I think that purposed solution might not make sense, because we need to raise a failure if an array is provided with values in properties, but maybe we can optimize for the array with 0 elements type case.

kimchy added a commit to kimchy/elasticsearch that referenced this issue May 1, 2014
kimchy added a commit that referenced this issue May 1, 2014
@kimchy
Copy link
Member

kimchy commented May 1, 2014

fixed in upcoming 1.2, see #6006

@edast
Copy link
Author

edast commented May 5, 2014

could you also change src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java (line 66) to support empty array for "fields"?

   } else if (fieldName.equals("fields")) {
       Map<String, Object> fieldsNode = (Map<String, Object>) fieldNode;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants