There is an api which returns a elastic search query with placeholders. Once this query string is obtained I need to update the placeholders and then create a SearchSourceBuilder instance. Using the searchInstance, I need to create a SearchRequest and hit the elastic search instance through restHighLevelClient.
But how do I create the SearchSourceBuilder instance, I have tried this following approach but getting the below error, not sure where, I am going wrong.
String queryString = //
JsonXContentParser xContentParser = new JsonXContentParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, new JsonFactory().createParser(s));
//below line throws the error
SearchSourceBuilder sourceBuilder = SearchSourceBuilder.fromXContent(xContentParser);
searchRequest.source(soruceBuilder)
restHighLevelClient.search(source,RequestOptions.DEFAULT);
Error: named objects are not supported for this parser
The error you get is when creating the
JsonXContentParser
not theSearchSourceBuilder
Try this: