Examples of XContentBuilder


Examples of org.elasticsearch.common.xcontent.XContentBuilder

    public XContentThrowableRestResponse(RestRequest request, RestStatus status, Throwable t) throws IOException {
        super(request, status, convert(request, status, t));
    }

    private static XContentBuilder convert(RestRequest request, RestStatus status, Throwable t) throws IOException {
        XContentBuilder builder = restContentBuilder(request).startObject()
                .field("error", detailedMessage(t))
                .field("status", status.getStatus());
        if (t != null && request.paramAsBoolean("error_trace", false)) {
            builder.startObject("error_trace");
            boolean first = true;
            while (t != null) {
                if (!first) {
                    builder.startObject("cause");
                }
                buildThrowable(t, builder);
                if (!first) {
                    builder.endObject();
                }
                t = t.getCause();
                first = false;
            }
            builder.endObject();
        }
        builder.endObject();
        return builder;
    }
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

    @Test public void testSmileRawField() throws IOException {
        testRawField(XContentType.SMILE);
    }

    private void testRawField(XContentType type) throws IOException {
        XContentBuilder builder = XContentFactory.contentBuilder(type);
        builder.startObject();
        builder.field("field1", "value1");
        builder.rawField("_source", XContentFactory.unCachedContentBuilder(type).startObject().field("s_field", "s_value").endObject().copiedBytes());
        builder.field("field2", "value2");
        builder.endObject();

        XContentParser parser = XContentFactory.xContent(type).createParser(builder.copiedBytes());
        assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
        assertThat(parser.nextToken(), equalTo(XContentParser.Token.FIELD_NAME));
        assertThat(parser.currentName(), equalTo("field1"));
        assertThat(parser.nextToken(), equalTo(XContentParser.Token.VALUE_STRING));
        assertThat(parser.text(), equalTo("value1"));
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

                }
        ).createInjector();

        final PercolatorExecutor percolatorExecutor = injector.getInstance(PercolatorExecutor.class);

        XContentBuilder doc = XContentFactory.jsonBuilder().startObject().startObject("doc")
                .field("field1", 1)
                .field("field2", "value")
                .field("field3", "the quick brown fox jumped over the lazy dog")
                .endObject().endObject();
        final byte[] source = doc.copiedBytes();

        PercolatorExecutor.Response percolate = percolatorExecutor.percolate(new PercolatorExecutor.SourceRequest("type1", source));

        for (int i = 0; i < NUMBER_OF_QUERIES; i++) {
            percolatorExecutor.addQuery("test" + i, termQuery("field3", "quick"));
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

        public MetaData build() {
            return new MetaData(version, indices.immutableMap(), templates.immutableMap());
        }

        public static String toXContent(MetaData metaData) throws IOException {
            XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
            builder.startObject();
            toXContent(metaData, builder, ToXContent.EMPTY_PARAMS);
            builder.endObject();
            return builder.string();
        }
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

                OutputStream fos = new FileOutputStream(stateFile);
                if (compress) {
                    fos = new LZFOutputStream(fos);
                }
                LocalGatewayMetaState stateToWrite = builder.build();
                XContentBuilder xContentBuilder = XContentFactory.contentBuilder(XContentType.JSON, fos);
                if (prettyPrint) {
                    xContentBuilder.prettyPrint();
                }
                xContentBuilder.startObject();
                LocalGatewayMetaState.Builder.toXContent(stateToWrite, xContentBuilder, ToXContent.EMPTY_PARAMS);
                xContentBuilder.endObject();
                xContentBuilder.close();
                fos.close();

                FileSystemUtils.syncFile(stateFile);

                currentMetaState = stateToWrite;
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

                OutputStream fos = new FileOutputStream(stateFile);
                if (compress) {
                    fos = new LZFOutputStream(fos);
                }

                XContentBuilder xContentBuilder = XContentFactory.contentBuilder(XContentType.JSON, fos);
                if (prettyPrint) {
                    xContentBuilder.prettyPrint();
                }
                xContentBuilder.startObject();
                LocalGatewayStartedShards.Builder.toXContent(stateToWrite, xContentBuilder, ToXContent.EMPTY_PARAMS);
                xContentBuilder.endObject();
                xContentBuilder.close();

                fos.close();

                FileSystemUtils.syncFile(stateFile);
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

            FastByteArrayOutputStream out = new FastByteArrayOutputStream();
            OutputStream os = out;
            if (compress) {
                os = new LZFOutputStream(os);
            }
            XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON, os);
            builder.startObject();
            MetaData.Builder.toXContent(metaData, builder, ToXContent.EMPTY_PARAMS);
            builder.endObject();
            builder.close();
            metaDataBlobContainer.writeBlob(newMetaData, new ByteArrayInputStream(out.unsafeByteArray(), 0, out.size()), out.size());
        } catch (IOException e) {
            throw new GatewayException("Failed to write metadata [" + newMetaData + "]", e);
        }
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

        old.clear();
    }

    public void addQuery(String name, QueryBuilder queryBuilder) throws ElasticSearchException {
        try {
            XContentBuilder builder = XContentFactory.smileBuilder()
                    .startObject().field("query", queryBuilder).endObject();
            BytesStream unsafeBytes = builder.unsafeStream();
            addQuery(name, unsafeBytes.unsafeByteArray(), 0, unsafeBytes.size());
        } catch (IOException e) {
            throw new ElasticSearchException("Failed to add query [" + name + "]", e);
        }
    }
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

        if (filter == null || filter.isEmpty()) {
            this.filter = null;
            return this;
        }
        try {
            XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
            builder.map(filter);
            this.filter = builder.string();
            return this;
        } catch (IOException e) {
            throw new ElasticSearchGenerationException("Failed to generate [" + filter + "]", e);
        }
    }
View Full Code Here

Examples of org.elasticsearch.common.xcontent.XContentBuilder

        if (filterBuilder == null) {
            this.filter = null;
            return this;
        }
        try {
            XContentBuilder builder = XContentFactory.jsonBuilder();
            filterBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
            builder.close();
            this.filter = builder.string();
            return this;
        } catch (IOException e) {
            throw new ElasticSearchGenerationException("Failed to build json for alias request", e);
        }
    }
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.