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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -