Examples of XContentBuilder


Examples of org.elasticsearch.common.xcontent.XContentBuilder

        if (event == null) {
          break;
        }

        XContentBuilder builder = serializer.getContentBuilder(event);
        IndexRequestBuilder request = client.prepareIndex(indexName, indexType)
            .setSource(builder);

        if (ttlMs > 0) {
          request.setTTL(ttlMs);
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

    headers.put("headerNameTwo", "headerValueTwo");
    headers.put("type", "sometype");
    Event event = EventBuilder.withBody(message.getBytes(charset));
    event.setHeaders(headers);

    XContentBuilder expected = jsonBuilder()
        .startObject();
            expected.field("@message", new String(message.getBytes(), charset));
            expected.field("@timestamp", new Date(timestamp));
            expected.field("@source", "flume_tail_src");
            expected.field("@type", "sometype");
            expected.field("@source_host", "test@localhost");
            expected.field("@source_path", "/tmp/test");

            expected.startObject("@fields");
                expected.field("timestamp", String.valueOf(timestamp));
                expected.field("src_path", "/tmp/test");
                expected.field("host", "test@localhost");
                expected.field("headerNameTwo", "headerValueTwo");
                expected.field("source", "flume_tail_src");
                expected.field("headerNameOne", "headerValueOne");
                expected.field("type", "sometype");
            expected.endObject();

        expected.endObject();

    XContentBuilder actual = fixture.getContentBuilder(event);
   
    JsonParser parser = new JsonParser();
    assertEquals(parser.parse(expected.string()),parser.parse(actual.string()));
  }
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

    headers.put("headerNameTwo", "headerValueTwo");
    headers.put("type", "sometype");
    Event event = EventBuilder.withBody(message.getBytes(charset));
    event.setHeaders(headers);

    XContentBuilder expected = jsonBuilder().
        startObject();
            expected.field("@message", new String(message.getBytes(), charset));
            expected.field("@timestamp", new Date(timestamp));
            expected.field("@source", "flume_tail_src");
            expected.field("@type", "sometype");
            expected.field("@source_host", "test@localhost");
            expected.field("@source_path", "/tmp/test");

            expected.startObject("@fields");
                expected.field("timestamp", String.valueOf(timestamp));
                expected.field("src_path", "/tmp/test");
                expected.field("host", "test@localhost");
                expected.field("headerNameTwo", "headerValueTwo");
                expected.field("source", "flume_tail_src");
                expected.field("headerNameOne", "headerValueOne");
                expected.field("type", "sometype");
            expected.endObject();

        expected.endObject();

    XContentBuilder actual = fixture.getContentBuilder(event);

    JsonParser parser = new JsonParser();
    assertEquals(parser.parse(expected.string()),parser.parse(actual.string()));
  }
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

  public static void addComplexField(XContentBuilder builder, String fieldName,
      XContentType contentType, byte[] data) throws IOException {
    XContentParser parser = null;
    try {
      XContentBuilder tmp = jsonBuilder();
      parser = XContentFactory.xContent(contentType).createParser(data);
      parser.nextToken();
      tmp.copyCurrentStructure(parser);
      builder.field(fieldName, tmp.string());
    } catch (JsonParseException ex) {
      // If we get an exception here the most likely cause is nested JSON that
      // can't be figured out in the body. At this point just push it through
      // as is, we have already added the field so don't do it again
      addSimpleField(builder, fieldName, data);
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

    headers.put("headerNameTwo", "headerValueTwo");
    headers.put("headerNameThree", "headerValueThree");
    Event event = EventBuilder.withBody(message.getBytes(charset));
    event.setHeaders(headers);

    XContentBuilder expected = jsonBuilder().startObject();
    expected.field("body", new String(message.getBytes(), charset));
    for (String headerName : headers.keySet()) {
      expected.field(headerName, new String(headers.get(headerName).getBytes(),
          charset));
    }
    expected.endObject();

    XContentBuilder actual = fixture.getContentBuilder(event);

    assertEquals(new String(expected.bytes().array()), new String(actual
        .bytes().array()));

  }
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

            String title = stripTitle(page.getTitle());
            if (logger.isTraceEnabled()) {
                logger.trace("page {} : {}", page.getID(), page.getTitle());
            }
            try {
                XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
                builder.field("title", title);
                builder.field("text", page.getText());
                builder.field("redirect", page.isRedirect());
                builder.field("redirect_page", page.getRedirectPage());
                builder.field("special", page.isSpecialPage());
                builder.field("stub", page.isStub());
                builder.field("disambiguation", page.isDisambiguationPage());

                builder.startArray("category");
                for (String s : page.getCategories()) {
                    builder.value(s);
                }
                builder.endArray();

                builder.startArray("link");
                for (String s : page.getLinks()) {
                    builder.value(s);
                }
                builder.endArray();

                builder.endObject();

                if (closed) {
                    logger.warn("river was closing while processing wikipedia page [{}]/[{}]. Operation skipped.",
                            page.getID(), page.getTitle());
                    return;
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

        .fromRestContentType(request.param("format", request.header("Content-Type")));
    if (contentType == null) {
      // default to JSON
      contentType = XContentType.JSON;
    }
    XContentBuilder builder = new XContentBuilder(XContentFactory.xContent(contentType), new BytesStreamOutput());
    if (request.paramAsBoolean("pretty", false)) {
      builder.prettyPrint().lfAtEnd();
    }
    String casing = request.param("case");
    if (casing != null && "camelCase".equals(casing)) {
      builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.CAMELCASE);
    } else {
      // we expect all REST interfaces to write results in underscore casing, so
      // no need for double casing
      builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.NONE);
    }
    return builder;
  }
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

   * @throws Exception
   */
  @Override
  public String getRiverOperationInfo(DiscoveryNode esNode, Date currentDate) throws Exception {

    XContentBuilder builder = jsonBuilder().prettyPrint();
    builder.startObject();
    builder.field("river_name", riverName().getName());
    builder.field("info_date", currentDate);
    builder.startObject("indexing");
    builder.field("state", closed ? "stopped" : "running");
    if (!closed)
      builder.field("last_restart", lastRestartDate);
    else if (permanentStopDate != null)
      builder.field("stopped_permanently", permanentStopDate);
    builder.endObject();
    if (esNode != null) {
      builder.startObject("node");
      builder.field("id", esNode.getId());
      builder.field("name", esNode.getName());
      builder.endObject();
    }
    if (coordinatorInstance != null) {
      List<SpaceIndexingInfo> currProjectIndexingInfo = coordinatorInstance.getCurrentSpaceIndexingInfo();
      if (currProjectIndexingInfo != null) {
        builder.startArray("current_indexing");
        for (SpaceIndexingInfo pi : currProjectIndexingInfo) {
          pi.buildDocument(builder, true, false);
        }
        builder.endArray();
      }
    }
    List<String> pkeys = getAllIndexedSpaceKeys();
    if (pkeys != null) {
      builder.startArray("indexed_spaces");
      for (String spaceKey : pkeys) {
        builder.startObject();
        builder.field(SpaceIndexingInfo.DOCFIELD_SPACE_KEY, spaceKey);
        SpaceIndexingInfo lastIndexing = getLastSpaceIndexingInfo(spaceKey);
        if (lastIndexing != null) {
          builder.field("last_indexing");
          lastIndexing.buildDocument(builder, false, true);
        }
        builder.endObject();
      }
      builder.endArray();
    }
    builder.endObject();
    return builder.string();
  }
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

   * @see #storeDatetimeValue(String, String, Date, BulkRequestBuilder)
   * @see #readDatetimeValue(String, String)
   */
  protected XContentBuilder storeDatetimeValueBuildDocument(String spaceKey, String propertyName, Date datetime)
      throws IOException {
    XContentBuilder builder = jsonBuilder().startObject();
    if (spaceKey != null)
      builder.field("spaceKey", spaceKey);
    builder.field("propertyName", propertyName).field(STORE_FIELD_VALUE, DateTimeUtils.formatISODateTime(datetime));
    builder.endObject();
    return builder;
  }
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

   */
  protected XContentBuilder prepareIndexedDocument(String spaceKey, Map<String, Object> documentRemote)
      throws Exception {
    String documentId = extractDocumentId(documentRemote);

    XContentBuilder out = jsonBuilder().startObject();
    addValueToTheIndexField(out, indexFieldForRiverName, riverName);
    addValueToTheIndexField(out, indexFieldForSpaceKey, spaceKey);
    addValueToTheIndexField(out, indexFieldForRemoteDocumentId, documentId);

    for (String indexFieldName : fieldsConfig.keySet()) {
      Map<String, String> fieldConfig = fieldsConfig.get(indexFieldName);
      addValueToTheIndex(out, indexFieldName, fieldConfig.get(CONFIG_FIELDS_REMOTEFIELD), documentRemote,
          fieldConfig.get(CONFIG_FIELDS_VALUEFILTER));
    }

    if (commentIndexingMode == CommentIndexingMode.EMBEDDED) {
      List<Map<String, Object>> comments = extractComments(documentRemote);
      if (comments != null && !comments.isEmpty()) {
        out.startArray(indexFieldForComments);
        for (Map<String, Object> comment : comments) {
          out.startObject();
          addCommonFieldsToCommentIndexedDocument(out, documentId, comment);
          out.endObject();
        }
        out.endArray();
      }
    }
    return out.endObject();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.