コード例 #1
0
  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);
  }
コード例 #2
0
  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);
  }
コード例 #3
0
  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);
  }