Check whether a field is an object or test

Some information from a YAML files are stored and it could be as string or object. So the field in the YAML file could be stored as:

field:
  valueAsString

or

field:
  valueAsObjet:
    property1
    property2

The index related to this was defined as:
"field":{"type":"keyword"}
But with this definition, this error is thrown:
message [ElasticsearchException[Elasticsearch exception [type=mapper_parsing_exception, reason=failed to parse [field]]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_state_exception, reason=Can't get text on a START_OBJECT at 1:2522]];]
When the field is an object.
I've tried to change the definition as:
"field":{"type":"object"}
But this error is thrown:
message [ElasticsearchException[Elasticsearch exception [type=mapper_parsing_exception, reason=object mapping for [features] tried to parse field [null] as object, but found a concrete value]]]
for those that are defined as string.
I was investigating some options, like creating dynamic templates, something like this:

dynamic_templates: [
        [
                features: [
                        path_match:   "field.*",
                        "match_mapping_type" : "string",
                        mapping: [
                            "type": "string"
                ]
            ]
        ],
        [
                featuresCloud: [
                        path_match:   "features.*",
                        "match_mapping_type" : "object",
                        mapping: [
                                "type": "object"
                        ]
                ]
        ]
]

But it doesn't work.
What I'm looking for is that for this index stores only information about values that are string or values that are object, but not storing properties, only taking into account the key. So in the former example, it's only needed to take into account "valueAsString" and "valueAsString", properties "property1" and "property2" are not needed to be processed and stored in ES.
Is that possible?

Maybe this is some kind related to this: Force an object type into a text field?, but in this case, I'm interested on storing the date, instead of disabling it.

Thanks a lot!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.