Jackson jsonGenerator generate Elasticsearch query DSL -
i new elasticserach , jackson json. there simple query(search index country) try use jsongenerator,
"{\n" + " \"query\" : {\n" + " \"match\": { \"exporting_country\":\"" + countrycode + "\"} \n" + "} \n"+ "}"
jsongenerator code,
jsongenerator jgenerator = jfactory.creategenerator(outputstream); jgenerator.writestartobject(); jgenerator.writefieldname("query"); jgenerator.writestartobject(); jgenerator.writefieldname("match"); jgenerator.writestringfield("exporting_country", countrycode); jgenerator.writeendobject(); jgenerator.writeendobject(); jgenerator.close();
it throws out error:
can not write field name, expecting value
you're missing call writestartobject
:
jsongenerator jgenerator = jfactory.creategenerator(outputstream); jgenerator.writestartobject(); jgenerator.writefieldname("query"); jgenerator.writestartobject(); jgenerator.writefieldname("match"); jgenerator.writestartobject(); <--- add jgenerator.writestringfield("exporting_country", countrycode); jgenerator.writeendobject(); <--- , jgenerator.writeendobject(); jgenerator.writeendobject(); jgenerator.close();
Comments
Post a Comment