Java Code Examples for org.elasticsearch.common.xcontent.XContentBuilderString

The following examples show how to use org.elasticsearch.common.xcontent.XContentBuilderString. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Elasticsearch   Source File: ClusterStatsIndices.java    License: Apache License 2.0 5 votes vote down vote up
private void addIntMinMax(XContentBuilderString field, int min, int max, double avg, XContentBuilder builder) throws IOException {
    builder.startObject(field);
    builder.field(Fields.MIN, min);
    builder.field(Fields.MAX, max);
    builder.field(Fields.AVG, avg);
    builder.endObject();
}
 
Example 2
Source Project: Elasticsearch   Source File: ClusterStatsIndices.java    License: Apache License 2.0 5 votes vote down vote up
private void addDoubleMinMax(XContentBuilderString field, double min, double max, double avg, XContentBuilder builder) throws IOException {
    builder.startObject(field);
    builder.field(Fields.MIN, min);
    builder.field(Fields.MAX, max);
    builder.field(Fields.AVG, avg);
    builder.endObject();
}
 
Example 3
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder array(XContentBuilderString name, String... values) throws IOException {
    startArray(name);
    for (String value : values) {
        value(value);
    }
    endArray();
    return this;
}
 
Example 4
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder array(XContentBuilderString name, Object... values) throws IOException {
    startArray(name);
    for (Object value : values) {
        value(value);
    }
    endArray();
    return this;
}
 
Example 5
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name) throws IOException {
    if (fieldCaseConversion == FieldCaseConversion.UNDERSCORE) {
        generator.writeFieldName(name.underscore());
    } else if (fieldCaseConversion == FieldCaseConversion.CAMELCASE) {
        generator.writeFieldName(name.camelCase());
    } else {
        generator.writeFieldName(name.underscore());
    }
    return this;
}
 
Example 6
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, FieldCaseConversion conversion) throws IOException {
    if (conversion == FieldCaseConversion.UNDERSCORE) {
        generator.writeFieldName(name.underscore());
    } else if (conversion == FieldCaseConversion.CAMELCASE) {
        generator.writeFieldName(name.camelCase());
    } else {
        generator.writeFieldName(name.underscore());
    }
    return this;
}
 
Example 7
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, char[] value, int offset, int length) throws IOException {
    field(name);
    if (value == null) {
        generator.writeNull();
    } else {
        generator.writeString(value, offset, length);
    }
    return this;
}
 
Example 8
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, String value) throws IOException {
    field(name);
    if (value == null) {
        generator.writeNull();
    } else {
        generator.writeString(value);
    }
    return this;
}
 
Example 9
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, String value, FieldCaseConversion conversion) throws IOException {
    field(name, conversion);
    if (value == null) {
        generator.writeNull();
    } else {
        generator.writeString(value);
    }
    return this;
}
 
Example 10
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, Integer value) throws IOException {
    field(name);
    if (value == null) {
        generator.writeNull();
    } else {
        generator.writeNumber(value.intValue());
    }
    return this;
}
 
Example 11
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, Long value) throws IOException {
    field(name);
    if (value == null) {
        generator.writeNull();
    } else {
        generator.writeNumber(value.longValue());
    }
    return this;
}
 
Example 12
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, Float value) throws IOException {
    field(name);
    if (value == null) {
        generator.writeNull();
    } else {
        generator.writeNumber(value.floatValue());
    }
    return this;
}
 
Example 13
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, Double value) throws IOException {
    field(name);
    if (value == null) {
        generator.writeNull();
    } else {
        generator.writeNumber(value);
    }
    return this;
}
 
Example 14
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, BigDecimal value, int scale, RoundingMode rounding, boolean toDouble) throws IOException {
    field(name);
    if (toDouble) {
        try {
            generator.writeNumber(value.setScale(scale, rounding).doubleValue());
        } catch (ArithmeticException e) {
            generator.writeString(value.toEngineeringString());
        }
    } else {
        generator.writeString(value.toEngineeringString());
    }
    return this;
}
 
Example 15
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, BytesReference value) throws IOException {
    field(name);
    if (!value.hasArray()) {
        value = value.toBytesArray();
    }
    generator.writeBinary(value.array(), value.arrayOffset(), value.length());
    return this;
}
 
Example 16
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, Text value) throws IOException {
    field(name);
    if (value.hasBytes() && value.bytes().hasArray()) {
        generator.writeUTF8String(value.bytes().array(), value.bytes().arrayOffset(), value.bytes().length());
        return this;
    }
    if (value.hasString()) {
        generator.writeString(value.string());
        return this;
    }
    // TODO: TextBytesOptimization we can use a buffer here to convert it? maybe add a request to jackson to support InputStream as well?
    BytesArray bytesArray = value.bytes().toBytesArray();
    generator.writeUTF8String(bytesArray.array(), bytesArray.arrayOffset(), bytesArray.length());
    return this;
}
 
Example 17
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, Iterable value) throws IOException {
    startArray(name);
    for (Object o : value) {
        value(o);
    }
    endArray();
    return this;
}
 
Example 18
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, String... value) throws IOException {
    startArray(name);
    for (String o : value) {
        value(o);
    }
    endArray();
    return this;
}
 
Example 19
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, Object... value) throws IOException {
    startArray(name);
    for (Object o : value) {
        value(o);
    }
    endArray();
    return this;
}
 
Example 20
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, int offset, int length, int... value) throws IOException {
    assert ((offset >= 0) && (value.length > length));
    startArray(name);
    for (int i = offset; i < length; i++) {
        value(value[i]);
    }
    endArray();
    return this;
}
 
Example 21
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, int... value) throws IOException {
    startArray(name);
    for (Object o : value) {
        value(o);
    }
    endArray();
    return this;
}
 
Example 22
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, long... value) throws IOException {
    startArray(name);
    for (Object o : value) {
        value(o);
    }
    endArray();
    return this;
}
 
Example 23
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, float... value) throws IOException {
    startArray(name);
    for (Object o : value) {
        value(o);
    }
    endArray();
    return this;
}
 
Example 24
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(XContentBuilderString name, double... value) throws IOException {
    startArray(name);
    for (Object o : value) {
        value(o);
    }
    endArray();
    return this;
}
 
Example 25
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder timeValueField(XContentBuilderString rawFieldName, XContentBuilderString readableFieldName, TimeValue timeValue) throws IOException {
    if (humanReadable) {
        field(readableFieldName, timeValue.toString());
    }
    field(rawFieldName, timeValue.millis());
    return this;
}
 
Example 26
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder timeValueField(XContentBuilderString rawFieldName, XContentBuilderString readableFieldName, long rawTime) throws IOException {
    if (humanReadable) {
        field(readableFieldName, new TimeValue(rawTime).toString());
    }
    field(rawFieldName, rawTime);
    return this;
}
 
Example 27
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder byteSizeField(XContentBuilderString rawFieldName, XContentBuilderString readableFieldName, ByteSizeValue byteSizeValue) throws IOException {
    if (humanReadable) {
        field(readableFieldName, byteSizeValue.toString());
    }
    field(rawFieldName, byteSizeValue.bytes());
    return this;
}
 
Example 28
Source Project: elasticsearch-xml   Source File: XmlXContentBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder byteSizeField(XContentBuilderString rawFieldName, XContentBuilderString readableFieldName, long rawSize) throws IOException {
    if (humanReadable) {
        field(readableFieldName, new ByteSizeValue(rawSize).toString());
    }
    field(rawFieldName, rawSize);
    return this;
}
 
Example 29
Source Project: es-amazon-s3-river   Source File: S3ManageAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception{
   if (logger.isDebugEnabled()){
      logger.debug("REST S3ManageAction called");
   }
   
   String rivername = request.param("rivername");
   String command = request.param("command");
   
   String status = null;
   if (START_COMMAND.equals(command)){
      status = "STARTED";
   } else if (STOP_COMMAND.equals(command)){
      status = "STOPPED";
   }
   
   try{
      if (status != null){
         XContentBuilder xb = jsonBuilder()
            .startObject()
               .startObject("amazon-s3")
                  .field("feedname", rivername)
                  .field("status", status)
               .endObject()
            .endObject();
         client.prepareIndex("_river", rivername, "_s3status").setSource(xb).execute().actionGet();
      }
      
      XContentBuilder builder = jsonBuilder();
      builder
         .startObject()
            .field(new XContentBuilderString("ok"), true)
         .endObject();
      channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
   } catch (IOException e) {
      onFailure(request, channel, e);
   }
}
 
Example 30
Source Project: Elasticsearch   Source File: Suggest.java    License: Apache License 2.0 4 votes vote down vote up
public Suggest(XContentBuilderString name) {
    this.name = name;
}