1

I want to make bulk insert in java with http post to Elasticsearch server. I initiate org.json.JSONObject from the json string, up to now everything is normal. However when I execute the post method, Elasticsearch return me that error:

MapperParsingException[failed to parse [replyContent.value]];nested: JsonParseException[Invalid UTF-8 middle byte

The string contains turkish characters such as: ü, ç, ş...

I tried this code:

JSONObject jObject=new JSONObject(new String(jsonString.toString().getBytes("ISO8859_9"), "UTF8"));

With this initialization, post has been worked, nevertheless, this time all the turkish characters were converted to ? character.

What could be the solution code for this problem, and where should it be? In initiation code of json object or when I post the json data?

Thanks

2
  • Can you maybe share your code? Commented Jan 10, 2014 at 16:15
  • The code is; String sb= new SearchService().execute("item", dateFormat.format(date)); JSONObject jo=new JSONObject(new String(sb.getBytes("ISO8859_1"), "UTF8")); Then when I post the json, I convert it back to string again with the method toString strBuffer.append(bindings.getJSONObject(i).toString() + "\n"); Commented Jan 13, 2014 at 8:11

1 Answer 1

2

The problem is not with elastic search but rather with json.

based on the json rfc 4627 - json string needs to be encoded as unicode, thus having

characters such as: ü, ç, ş...

is invalid json

Sign up to request clarification or add additional context in comments.

2 Comments

So, what is the correct code for this? I wrote down the code I used.
@hakki first make sure that your string does not contain invalid characters (from json perspective), then you should be ok

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.