Failed to close the XContentBuilder

Hi guys, I'm presenting an error to install the plugin or make a query.

Code:

@Override
    public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    	builder.startObject(simpleName());
        builder.field("type", CONTENT_TYPE);
        startDateMapper.toXContent(builder, params);
        endDateMapper.toXContent(builder, params);
        rruleMapper.toXContent(builder, params);
        multiFields.toXContent(builder, params);
        builder.endObject();
        return builder;
    }

Error:

{
  "error": {
    "root_cause": [
      {
        "type": "parse_exception",
        "reason": "Failed to parse content to map",
        "suppressed": [
          {
            "type": "illegal_state_exception",
            "reason": "Failed to close the XContentBuilder"
          }
        ]
      }
    ],
    "type": "parse_exception",
    "reason": "Failed to parse content to map",
    "caused_by": {
      "type": "json_parse_exception",
      "reason": "Duplicate field 'recurrent_date'\n at [Source: org.elasticsearch.common.compress.DeflateCompressor$1@11d6fb74; line: 1, column: 102]"
    },
    "suppressed": [
      {
        "type": "illegal_state_exception",
        "reason": "Failed to close the XContentBuilder",
        "caused_by": {
          "type": "i_o_exception",
          "reason": "Unclosed object or array found"
        }
      }
    ]
  },
  "status": 400
}

Do you have any idea why?

A guess based on:

Duplicate field 'recurrent_date'

You have a duplicated field?

Hello, in my map I only have a recurring_date field specified. and this is the error that I have.

if you can give a view to my code. : D
link: https://github.com/EliuFlorez/recurring-plugin

JSON:

PUT example_event
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "number_of_replicas": 0
    },
    "analysis": {
      "analyzer": {
        "std_lang": {
          "type": "standard",
          "stopwords": "_english_"
        }
      }
    }
  },
  "mappings": {
    "event": {
      "properties": {
        "name": {
          "type": "text",
          "analyzer": "std_lang"
        },
        "recurrent_date": {
          "type": "recurring"
        }
      }
    }
  }
}

Error:

{
  "error": {
    "root_cause": [
      {
        "type": "generation_exception",
        "reason": "failed to serialize source for type [event]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Failed to parse mapping [event]: failed to serialize source for type [event]",
    "caused_by": {
      "type": "generation_exception",
      "reason": "failed to serialize source for type [event]",
      "caused_by": {
        "type": "illegal_state_exception",
        "reason": "Failed to close the XContentBuilder",
        "caused_by": {
          "type": "i_o_exception",
          "reason": "Unclosed object or array found"
        },
        "suppressed": [
          {
            "type": "illegal_state_exception",
            "reason": "Failed to close the XContentBuilder",
            "caused_by": {
              "type": "i_o_exception",
              "reason": "Unclosed object or array found"
            }
          }
        ]
      }
    }
  },
  "status": 400
}

This is not the same error message that you originally pasted. I guess you changed things in the meantime.

Anyway here the problem is that the generated json is not correctly formed. You are missing something similar to a } or a ].

Hello, in what way can I print the constructor to see so that the structure is generated and closes me.

I'm trying with:

throw new IllegalArgumentException("builder.toString:" + builder.toString());

but did not print the json string or structure created.

I guess it can't because your XContentBuilder object is not properly closed.

If I still have an error there is and it is so simple. and if I delete "public XContentBuilder toXContent ()" from my code, what difference did it open?

I don't understand the question.

The question is that if you delete from my "toXContent"

startDateMapper.toXContent(builder, params);
        endDateMapper.toXContent(builder, params);
        rruleMapper.toXContent(builder, params);
        multiFields.toXContent(builder, params);

it would be like that:

public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    	builder.startObject(simpleName());
        builder.field("type", CONTENT_TYPE);
        builder.endObject();
        return builder;
    }

it works to create the mapper. I do not know if it affects something else as in the results of the query that the plugin should return.

I don't know.

:sob:

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