Package org.elasticsearch.common.xcontent

Examples of org.elasticsearch.common.xcontent.XContentBuilder.bytes()


                    }
                } else if("context".equals(fieldName)) {
                    // Copy the current structure. We will parse, once the mapping is provided
                    XContentBuilder builder = XContentFactory.contentBuilder(parser.contentType());
                    builder.copyCurrentStructure(parser);
                    BytesReference bytes = builder.bytes();              
                    contextParser = parser.contentType().xContent().createParser(bytes);
                } else {
                    throw new ElasticsearchIllegalArgumentException("suggester [completion] doesn't support field [" + fieldName + "]");
                }
            } else {
View Full Code Here


        DocumentMapper enabledMapper = createIndex("test").mapperService().documentMapperParser().parse(enabledMapping);

        XContentBuilder builder = JsonXContent.contentBuilder().startObject();
        enabledMapper.timestampFieldMapper().toXContent(builder, ToXContent.EMPTY_PARAMS).endObject();
        builder.close();
        Map<String, Object> serializedMap = JsonXContent.jsonXContent.createParser(builder.bytes()).mapAndClose();
        assertThat(serializedMap, hasKey("_timestamp"));
        assertThat(serializedMap.get("_timestamp"), instanceOf(Map.class));
        Map<String, Object> timestampConfiguration = (Map<String, Object>) serializedMap.get("_timestamp");
        assertThat(timestampConfiguration, hasKey("index"));
        assertThat(timestampConfiguration.get("index").toString(), is("no"));
View Full Code Here

                doc = doc.field(fieldName, s);
            }

            doc = doc.endObject();

            final ParsedDocument d = mapper.parse("type", Integer.toString(i), doc.bytes());

            writer.addDocument(d.rootDoc());

            if (random.nextInt(10) == 0) {
                refreshReader();
View Full Code Here

                }
                doc = doc.endArray();
            }
            doc = doc.endObject();

            final ParsedDocument d = mapper.parse("type", Integer.toString(i), doc.bytes());

            writer.addDocument(d.rootDoc());
            if (random.nextInt(10) == 0) {
                refreshReader();
            }
View Full Code Here

            for (int j = 0; j < numValues; ++j) {
                doc = doc.value(values[j]);
            }
            doc = doc.endArray().endObject();

            final ParsedDocument d = mapper.parse("type", Integer.toString(i), doc.bytes());

            writer.addDocument(d.rootDoc());
            if (random.nextInt(10) == 0) {
                refreshReader();
            }
View Full Code Here

                } else {
                    doc.startObject().field("lat", randomDouble() * 180 - 90).field("lon", randomDouble() * 360 - 180).endObject();
                }
            }
            doc = doc.endArray().endObject();
            final ParsedDocument d = mapper.parse("type", Integer.toString(i), doc.bytes());

            writer.addDocument(d.rootDoc());
            if (random.nextInt(10) == 0) {
                refreshReader();
            }
View Full Code Here

                    .startObject()
                        .field("bar", "Elasticsearch rules!")
                    .endObject()
                .endObject();

        Document doc = docMapper.parse(builder.bytes()).rootDoc();
        AllField field = (AllField) doc.getField("_all");
        AllEntries allEntries = field.getAllEntries();
        assertThat(allEntries.fields(), empty());
    }
View Full Code Here

                .startObject()
                .field("bar", "Elasticsearch rules!")
                .endObject()
                .endObject();

        Document doc = docMapper.parse(builder.bytes()).rootDoc();
        AllField field = (AllField) doc.getField("_all");
        AllEntries allEntries = field.getAllEntries();
        assertThat(allEntries.fields(), hasSize(1));
        assertThat(allEntries.fields(), hasItem("foo.bar"));
    }
View Full Code Here

        // Check json serialization
        StringFieldMapper stringFieldMapper = (StringFieldMapper) fieldMapper;
        XContentBuilder builder = jsonBuilder().startObject();
        stringFieldMapper.toXContent(builder, ToXContent.EMPTY_PARAMS).endObject();
        builder.close();
        Map<String, Object> serializedMap = JsonXContent.jsonXContent.createParser(builder.bytes()).mapAndClose();
        Map<String, Object> copyTestMap = (Map<String, Object>) serializedMap.get("copy_test");
        assertThat(copyTestMap.get("type").toString(), is("string"));
        List<String> copyToList = (List<String>) copyTestMap.get("copy_to");
        assertThat(copyToList.size(), equalTo(2));
        assertThat(copyToList.get(0).toString(), equalTo("another_field"));
View Full Code Here

                                .endArray()
                            .endObject()
                        .endArray()
                    .endObject();

            ParsedDocument doc = mapper.parse("type", "1", jsonDoc.bytes());
            assertEquals(6, doc.docs().size());

            Document nested = doc.docs().get(0);
            assertFieldValue(nested, "n1.n2.target", 7L);
            assertFieldValue(nested, "n1.target");
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.