Package org.elasticsearch.common.xcontent

Examples of org.elasticsearch.common.xcontent.XContentParser.map()


                                continue;
                            }
                            foundType = true;
                            byte[] mappingSource = mappingMd.source().uncompressed();
                            XContentParser parser = XContentFactory.xContent(mappingSource).createParser(mappingSource);
                            Map<String, Object> mapping = parser.map();
                            if (mapping.size() == 1 && mapping.containsKey(mappingMd.type())) {
                                // the type name is the root value, reduce it
                                mapping = (Map<String, Object>) mapping.get(mappingMd.type());
                            }
                            builder.field(mappingMd.type());
View Full Code Here


                                    // filter this type out...
                                    continue;
                                }
                                byte[] mappingSource = mappingMd.source().uncompressed();
                                XContentParser parser = XContentFactory.xContent(mappingSource).createParser(mappingSource);
                                Map<String, Object> mapping = parser.map();
                                if (mapping.size() == 1 && mapping.containsKey(mappingMd.type())) {
                                    // the type name is the root value, reduce it
                                    mapping = (Map<String, Object>) mapping.get(mappingMd.type());
                                }
                                builder.field(mappingMd.type());
View Full Code Here

                BytesStreamInput siBytes = new BytesStreamInput(bytes, offset, length);
                LZFStreamInput siLzf = CachedStreamInput.cachedLzf(siBytes);
                XContentType contentType = XContentFactory.xContentType(siLzf);
                siLzf.resetToBufferStart();
                parser = XContentFactory.xContent(contentType).createParser(siLzf);
                return parser.map();
            } else {
                parser = XContentFactory.xContent(bytes, offset, length).createParser(bytes, offset, length);
                return parser.map();
            }
        } catch (Exception e) {
View Full Code Here

                siLzf.resetToBufferStart();
                parser = XContentFactory.xContent(contentType).createParser(siLzf);
                return parser.map();
            } else {
                parser = XContentFactory.xContent(bytes, offset, length).createParser(bytes, offset, length);
                return parser.map();
            }
        } catch (Exception e) {
            throw new ElasticSearchParseException("Failed to parse source to map", e);
        } finally {
            if (parser != null) {
View Full Code Here

        super(settings, client);
        Map<String, Object> rootNode;
        int quotesSize;
        try {
            XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(Classes.getDefaultClassLoader().getResourceAsStream("org/elasticsearch/rest/action/main/quotes.json"));
            rootNode = parser.map();
            List arrayNode = (List) rootNode.get("quotes");
            quotesSize = arrayNode.size();
        } catch (Exception e) {
            rootNode = null;
            quotesSize = -1;
View Full Code Here

            builder.startObject("mappings");
            for (Map.Entry<String, CompressedString> entry : indexMetaData.mappings().entrySet()) {
                byte[] mappingSource = entry.getValue().uncompressed();
                XContentParser parser = XContentFactory.xContent(mappingSource).createParser(mappingSource);
                Map<String, Object> mapping = parser.map();
                if (mapping.size() == 1 && mapping.containsKey(entry.getKey())) {
                    // the type name is the root value, reduce it
                    mapping = (Map<String, Object>) mapping.get(entry.getKey());
                }
                builder.field(entry.getKey());
View Full Code Here

        this.id = id;
    }

    private static Map<String, Object> asMap(String jsonSource) throws IOException {
        XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(jsonSource);
        return parser.map();
    }

    private static String asString(Map<String, Object> map) throws IOException {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        return builder.map(map).string();
View Full Code Here

    private Map<String, Object> parse(String source) {
        Map<String, Object> map = null;
        XContentParser parser = null;
        try {
            parser = XContentFactory.xContent(source).createParser(source);
            map = parser.map();
        } catch (Exception e) {
            logger.error("unable to parse: {}", source);
        } finally {
            if (parser != null) {
                parser.close();
View Full Code Here

            Map<String, Object> map = null;
            String message = request.content().toUtf8();
            XContentParser parser = null;
            try {
                parser = XContentFactory.xContent(message).createParser(message);
                map = parser.map();
            } catch (Exception e) {
                logger.warn("unable to parse {}", message);
            } finally {
                parser = null;
            }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    private List<String> getSuggestionsFromResponse(String response) throws IOException {
        XContentParser parser = JsonXContent.jsonXContent.createParser(response);
        Map<String, Object> jsonResponse = parser.map();
        assertThat(jsonResponse, hasKey("suggestions"));
        return (List<String>) jsonResponse.get("suggestions");
    }

}
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.