Examples of XContentBuilder


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

    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);
    assertEquals(new String(expected.bytes().array()), new String(actual
        .bytes().array()));
  }
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);
    assertEquals(new String(expected.bytes().array()), new String(actual
        .bytes().array()));
  }
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

    /**
     * Index a parent doc
     */
    public void indexParent(String id, Map<String, Object> objectMap) throws IOException {
        XContentBuilder builder = XContentFactory.jsonBuilder();

        // index content
        client.prepareIndex(INDEX_NAME, PARENT_TYPE_NAME, id).setSource(builder.map(objectMap)).execute().actionGet();
    }
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

    /**
     * Index the file as a child doc
     */
    public void indexChild(String id, Map<String, Object> objectMap) throws IOException {
        XContentBuilder builder = XContentFactory.jsonBuilder();

        IndexRequestBuilder indexRequestbuilder = client.prepareIndex(INDEX_NAME, CHILD_TYPE_NAME, id);
        indexRequestbuilder = indexRequestbuilder.setParent(id);
        indexRequestbuilder = indexRequestbuilder.setSource(builder.map(objectMap));
        indexRequestbuilder.execute().actionGet();
    }
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

        }
    }

    private void indexDoc() throws Exception {
        StringBuffer sb = new StringBuffer();
        XContentBuilder json = XContentFactory.jsonBuilder().startObject()
                .field("field", "value" + ThreadLocalRandom.current().nextInt());

        int fields = Math.abs(ThreadLocalRandom.current().nextInt()) % numberOfFields;
        for (int i = 0; i < fields; i++) {
            json.field("num_" + i, ThreadLocalRandom.current().nextDouble());
            int tokens = ThreadLocalRandom.current().nextInt() % textTokens;
            sb.setLength(0);
            for (int j = 0; j < tokens; j++) {
                sb.append(UUID.randomBase64UUID()).append(' ');
            }
            json.field("text_" + i, sb.toString());
        }

        json.endObject();

        String id = Long.toString(idCounter.incrementAndGet());
        client.client().prepareIndex("test", "type1", id)
                .setCreate(true)
                .setSource(json)
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

            }
        }
    }

    private void indexDoc() throws Exception {
        XContentBuilder json = XContentFactory.jsonBuilder().startObject()
                .field("num", nextNumValue())
                .field("field", nextFieldValue());

        json.endObject();

        client.client().prepareIndex(nextIndex(), nextType())
                .setSource(json)
                .execute().actionGet();
        indexCounter.incrementAndGet();
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

            int numberOfBulks = numberOfDocsPerRound / bulkSize;
            for (int b = 0; b < numberOfBulks; b++) {
                BulkRequestBuilder bulk = client.client().prepareBulk();
                for (int k = 0; k < bulkSize; k++) {
                    StringBuffer sb = new StringBuffer();
                    XContentBuilder json = XContentFactory.jsonBuilder().startObject()
                            .field("field", "value" + ThreadLocalRandom.current().nextInt());

                    int fields = ThreadLocalRandom.current().nextInt() % numberOfFields;
                    for (int i = 0; i < fields; i++) {
                        json.field("num_" + i, ThreadLocalRandom.current().nextDouble());
                        int tokens = ThreadLocalRandom.current().nextInt() % textTokens;
                        sb.setLength(0);
                        for (int j = 0; j < tokens; j++) {
                            sb.append(UUID.randomBase64UUID()).append(' ');
                        }
                        json.field("text_" + i, sb.toString());
                    }

                    json.endObject();

                    bulk.add(Requests.indexRequest("test" + (Math.abs(ThreadLocalRandom.current().nextInt()) % numberOfIndices)).type("type1").source(json));
                    indexCounter.incrementAndGet();
                }
                bulk.execute().actionGet();
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.