public void testParserCanExtractTemplateNames() throws Exception { String templateString = "{ \"file\": \"storedTemplate\" ,\"params\":{\"template\":\"all\" } } "; XContentParser templateSourceParser = XContentFactory.xContent(templateString).createParser(templateString); context.reset(); templateSourceParser.nextToken(); Query query = QueryBuilder.rewriteQuery( TemplateQueryBuilder.fromXContent(context.newParseContext(templateSourceParser)), context) .toQuery(context); assertTrue("Parsing template query failed.", query instanceof MatchAllDocsQuery); }
public void testParser() throws IOException { String templateString = "{" + "\"query\":{\"match_{{template}}\": {}}," + "\"params\":{\"template\":\"all\"}" + "}"; XContentParser templateSourceParser = XContentFactory.xContent(templateString).createParser(templateString); context.reset(); templateSourceParser.nextToken(); Query query = QueryBuilder.rewriteQuery( TemplateQueryBuilder.fromXContent(context.newParseContext(templateSourceParser)), context) .toQuery(context); assertTrue("Parsing template query failed.", query instanceof MatchAllDocsQuery); }
public void testParseTemplateAsSingleStringWithConditionalClause() throws IOException { String templateString = "{" + " \"inline\" : \"{ \\\"match_{{#use_it}}{{template}}{{/use_it}}\\\":{} }\"," + " \"params\":{" + " \"template\":\"all\"," + " \"use_it\": true" + " }" + "}"; XContentParser templateSourceParser = XContentFactory.xContent(templateString).createParser(templateString); context.reset(); Query query = QueryBuilder.rewriteQuery( TemplateQueryBuilder.fromXContent(context.newParseContext(templateSourceParser)), context) .toQuery(context); assertTrue("Parsing template query failed.", query instanceof MatchAllDocsQuery); }