Elasticsearch: 6.1.2
I have an input query via JSON and would like to use the high level Java API to construct a search request using that query data.
String jsonQuery = "..."
SearchRequest searchRequest = new SearchRequest()
SearchSourceBuilder builder = ?
searchRequest.source(builder);
I tried to construct the builder via:
SearchSourceBuilder.fromXContent(XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, query));
but that yields:
Caused by: org.elasticsearch.ElasticsearchException: namedObject is not supported for this parser at org.elasticsearch.common.xcontent.NamedXContentRegistry.parseNamedObject(NamedXContentRegistry.java:129) ~[elasticsearch-6.1.2.jar:6.1.2] at org.elasticsearch.common.xcontent.support.AbstractXContentParser.namedObject(AbstractXContentParser.java:402) ~[elasticsearch-6.1.2.jar:6.1.2] at org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder(AbstractQueryBuilder.java:313) ~[elasticsearch-6.1.2.jar:6.1.2] at org.elasticsearch.search.builder.SearchSourceBuilder.parseXContent(SearchSourceBuilder.java:1003) ~[elasticsearch-6.1.2.jar:6.1.2] at org.elasticsearch.search.builder.SearchSourceBuilder.fromXContent(SearchSourceBuilder.java:115) ~[elasticsearch-6.1.2.jar:6.1.2]