当前位置: 首页>>代码示例>>Java>>正文


Java BytesReference类代码示例

本文整理汇总了Java中org.elasticsearch.common.bytes.BytesReference的典型用法代码示例。如果您正苦于以下问题:Java BytesReference类的具体用法?Java BytesReference怎么用?Java BytesReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BytesReference类属于org.elasticsearch.common.bytes包,在下文中一共展示了BytesReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testBasics

import org.elasticsearch.common.bytes.BytesReference; //导入依赖的package包/类
public void testBasics() {
    String template = "GET _search {\"query\": " + "{\"boosting\": {"
        + "\"positive\": {\"match\": {\"body\": \"gift\"}},"
        + "\"negative\": {\"term\": {\"body\": {\"value\": \"solr\"}"
        + "}}, \"negative_boost\": {{boost_val}} } }}";
    Map<String, Object> params = Collections.singletonMap("boost_val", "0.2");

    Mustache mustache = (Mustache) engine.compile(null, template, Collections.emptyMap());
    CompiledScript compiledScript = new CompiledScript(INLINE, "my-name", "mustache", mustache);
    ExecutableScript result = engine.executable(compiledScript, params);
    assertEquals(
            "Mustache templating broken",
            "GET _search {\"query\": {\"boosting\": {\"positive\": {\"match\": {\"body\": \"gift\"}},"
                    + "\"negative\": {\"term\": {\"body\": {\"value\": \"solr\"}}}, \"negative_boost\": 0.2 } }}",
            ((BytesReference) result.run()).utf8ToString()
    );
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:MustacheTests.java

示例2: testParser

import org.elasticsearch.common.bytes.BytesReference; //导入依赖的package包/类
public void testParser() throws IOException {
    ContextParser<Void, PipelineConfiguration> parser = PipelineConfiguration.getParser();
    XContentType xContentType = randomFrom(XContentType.values());
    final BytesReference bytes;
    try (XContentBuilder builder = XContentBuilder.builder(xContentType.xContent())) {
        new PipelineConfiguration("1", new BytesArray("{}".getBytes(StandardCharsets.UTF_8)), XContentType.JSON)
            .toXContent(builder, ToXContent.EMPTY_PARAMS);
        bytes = builder.bytes();
    }

    XContentParser xContentParser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, bytes);
    PipelineConfiguration parsed = parser.parse(xContentParser, null);
    assertEquals(xContentType, parsed.getXContentType());
    assertEquals("{}", XContentHelper.convertToJson(parsed.getConfig(), false, parsed.getXContentType()));
    assertEquals("1", parsed.getId());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:PipelineConfigurationTests.java

示例3: toByteBuf

import org.elasticsearch.common.bytes.BytesReference; //导入依赖的package包/类
/**
 * Turns the given BytesReference into a ByteBuf. Note: the returned ByteBuf will reference the internal
 * pages of the BytesReference. Don't free the bytes of reference before the ByteBuf goes out of scope.
 */
public static ByteBuf toByteBuf(final BytesReference reference) {
    if (reference.length() == 0) {
        return Unpooled.EMPTY_BUFFER;
    }
    if (reference instanceof ByteBufBytesReference) {
        return ((ByteBufBytesReference) reference).toByteBuf();
    } else {
        final BytesRefIterator iterator = reference.iterator();
        // usually we have one, two, or three components from the header, the message, and a buffer
        final List<ByteBuf> buffers = new ArrayList<>(3);
        try {
            BytesRef slice;
            while ((slice = iterator.next()) != null) {
                buffers.add(Unpooled.wrappedBuffer(slice.bytes, slice.offset, slice.length));
            }
            final CompositeByteBuf composite = Unpooled.compositeBuffer(buffers.size());
            composite.addComponents(true, buffers);
            return composite;
        } catch (IOException ex) {
            throw new AssertionError("no IO happens here", ex);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:Netty4Utils.java

示例4: readFrom

import org.elasticsearch.common.bytes.BytesReference; //导入依赖的package包/类
@Override
public IndexWarmersMetaData readFrom(StreamInput in) throws IOException {
    Entry[] entries = new Entry[in.readVInt()];
    for (int i = 0; i < entries.length; i++) {
        String name = in.readString();
        String[] types = in.readStringArray();
        BytesReference source = null;
        if (in.readBoolean()) {
            source = in.readBytesReference();
        }
        Boolean queryCache;
        queryCache = in.readOptionalBoolean();
        entries[i] = new Entry(name, types, queryCache, source);
    }
    return new IndexWarmersMetaData(entries);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:IndexWarmersMetaData.java

示例5: convertToJson

import org.elasticsearch.common.bytes.BytesReference; //导入依赖的package包/类
public static String convertToJson(BytesReference bytes, boolean reformatJson, boolean prettyPrint) throws IOException {
    if (bytes.hasArray()) {
        return convertToJson(bytes.array(), bytes.arrayOffset(), bytes.length(), reformatJson, prettyPrint);
    }
    XContentType xContentType = XContentFactory.xContentType(bytes);
    if (xContentType == XContentType.JSON && !reformatJson) {
        BytesArray bytesArray = bytes.toBytesArray();
        return new String(bytesArray.array(), bytesArray.arrayOffset(), bytesArray.length(), Charsets.UTF_8);
    }
    try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(bytes.streamInput())) {
        parser.nextToken();
        XContentBuilder builder = XContentFactory.jsonBuilder();
        if (prettyPrint) {
            builder.prettyPrint();
        }
        builder.copyCurrentStructure(parser);
        return builder.string();
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:20,代码来源:XContentHelper.java

示例6: testDynamicDateDetectionEnabledWithNoSpecialCharacters

import org.elasticsearch.common.bytes.BytesReference; //导入依赖的package包/类
public void testDynamicDateDetectionEnabledWithNoSpecialCharacters() throws IOException {
    DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startArray("dynamic_date_formats")
                .value("yyyy MM")
            .endArray().endObject().endObject().string();
    DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping));

    BytesReference bytes = XContentFactory.jsonBuilder()
        .startObject()
            .field("foo", "2016 12")
        .endObject().bytes();

    // We should have generated a date field
    ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
    Mapping update = doc.dynamicMappingsUpdate();
    assertNotNull(update);
    Mapper dateMapper = update.root().getMapper("foo");
    assertNotNull(dateMapper);
    assertThat(dateMapper, instanceOf(DateFieldMapper.class));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:DocumentParserTests.java

示例7: testDynamicDottedFieldNameLongArray

import org.elasticsearch.common.bytes.BytesReference; //导入依赖的package包/类
public void testDynamicDottedFieldNameLongArray() throws Exception {
    DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
        .endObject().endObject().string();
    DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping));

    BytesReference bytes = XContentFactory.jsonBuilder()
        .startObject().startArray("foo.bar.baz")
            .value(0)
            .value(1)
        .endArray().endObject().bytes();
    ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
    assertEquals(4, doc.rootDoc().getFields("foo.bar.baz").length);
    Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
    assertNotNull(fooMapper);
    assertThat(fooMapper, instanceOf(ObjectMapper.class));
    Mapper barMapper = ((ObjectMapper) fooMapper).getMapper("bar");
    assertNotNull(barMapper);
    assertThat(barMapper, instanceOf(ObjectMapper.class));
    Mapper bazMapper = ((ObjectMapper) barMapper).getMapper("baz");
    assertNotNull(bazMapper);
    assertThat(bazMapper, instanceOf(NumberFieldMapper.class));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:DocumentParserTests.java

示例8: testSingleShortPageBulkWrite

import org.elasticsearch.common.bytes.BytesReference; //导入依赖的package包/类
public void testSingleShortPageBulkWrite() throws Exception {
    BytesStreamOutput out = new BytesStreamOutput();

    // first bulk-write empty array: should not change anything
    int expectedSize = 0;
    byte[] expectedData = randomizedByteArrayWithSize(expectedSize);
    out.writeBytes(expectedData);
    assertEquals(expectedSize, out.size());
    assertArrayEquals(expectedData, BytesReference.toBytes(out.bytes()));

    // bulk-write again with actual bytes
    expectedSize = 10;
    expectedData = randomizedByteArrayWithSize(expectedSize);
    out.writeBytes(expectedData);
    assertEquals(expectedSize, out.size());
    assertArrayEquals(expectedData, BytesReference.toBytes(out.bytes()));

    out.close();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:BytesStreamsTests.java

示例9: testMultiFields

import org.elasticsearch.common.bytes.BytesReference; //导入依赖的package包/类
public void testMultiFields() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties")
                .startObject("field")
                    .field("type", "boolean")
                    .startObject("fields")
                        .startObject("as_string")
                            .field("type", "keyword")
                        .endObject()
                    .endObject()
                .endObject().endObject()
            .endObject().endObject().string();
    DocumentMapper mapper = indexService.mapperService()
        .merge("type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE, false);
    assertEquals(mapping, mapper.mappingSource().toString());
    BytesReference source = XContentFactory.jsonBuilder()
            .startObject()
                .field("field", false)
            .endObject().bytes();
    ParsedDocument doc = mapper.parse("test", "type", "1", source);
    assertNotNull(doc.rootDoc().getField("field.as_string"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:BooleanFieldMapperTests.java

示例10: prepareRequest

import org.elasticsearch.common.bytes.BytesReference; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    String id = request.param("id");
    String lang = request.param("lang");

    // In the case where only {lang} is not null, we make it {id} because of
    // name ordering issues in the handlers' paths.
    if (id == null) {
        id = lang;
        lang = null;
    }

    BytesReference content = request.content();

    if (lang != null) {
        deprecationLogger.deprecated(
            "specifying lang [" + lang + "] as part of the url path is deprecated, use request content instead");
    }

    PutStoredScriptRequest putRequest = new PutStoredScriptRequest(id, lang, content, request.getXContentType());
    return channel -> client.admin().cluster().putStoredScript(putRequest, new AcknowledgedRestListener<>(channel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:RestPutStoredScriptAction.java

示例11: testFromXContent

import org.elasticsearch.common.bytes.BytesReference; //导入依赖的package包/类
public void testFromXContent() throws IOException {
    MainResponse mainResponse = createTestItem();
    XContentType xContentType = randomFrom(XContentType.values());
    boolean humanReadable = randomBoolean();
    BytesReference originalBytes = toXContent(mainResponse, xContentType, humanReadable);
    MainResponse parsed;
    try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
        parsed = MainResponse.fromXContent(parser);
        assertNull(parser.nextToken());
    }
    assertEquals(mainResponse.getClusterUuid(), parsed.getClusterUuid());
    assertEquals(mainResponse.getClusterName(), parsed.getClusterName());
    assertEquals(mainResponse.getNodeName(), parsed.getNodeName());
    assertEquals(mainResponse.getBuild(), parsed.getBuild());
    assertEquals(mainResponse.getVersion(), parsed.getVersion());
    // we cannot recreate the "available" flag from xContent, but should be "true" if request came through
    assertEquals(true, parsed.isAvailable());
    assertToXContentEquivalent(originalBytes, toXContent(parsed, xContentType, humanReadable), xContentType);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:MainResponseTests.java

示例12: testDynamicDottedFieldNameObjectWithExistingParent

import org.elasticsearch.common.bytes.BytesReference; //导入依赖的package包/类
public void testDynamicDottedFieldNameObjectWithExistingParent() throws Exception {
    DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("foo")
            .field("type", "object").endObject().endObject().endObject().endObject().string();
    DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping));

    BytesReference bytes = XContentFactory.jsonBuilder().startObject().startObject("foo.bar.baz").field("a", 0).endObject().endObject()
            .bytes();
    ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
    assertEquals(2, doc.rootDoc().getFields("foo.bar.baz.a").length);
    Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
    assertNotNull(fooMapper);
    assertThat(fooMapper, instanceOf(ObjectMapper.class));
    Mapper barMapper = ((ObjectMapper) fooMapper).getMapper("bar");
    assertNotNull(barMapper);
    assertThat(barMapper, instanceOf(ObjectMapper.class));
    Mapper bazMapper = ((ObjectMapper) barMapper).getMapper("baz");
    assertNotNull(bazMapper);
    assertThat(bazMapper, instanceOf(ObjectMapper.class));
    Mapper aMapper = ((ObjectMapper) bazMapper).getMapper("a");
    assertNotNull(aMapper);
    assertThat(aMapper, instanceOf(NumberFieldMapper.class));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:DocumentParserTests.java

示例13: testFromXContent

import org.elasticsearch.common.bytes.BytesReference; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void testFromXContent() throws IOException {
    for (Class<? extends Entry> entryType : ENTRY_PARSERS.keySet()) {
        Entry<Option> entry = createTestItem(entryType);
        XContentType xContentType = randomFrom(XContentType.values());
        boolean humanReadable = randomBoolean();
        BytesReference originalBytes = toXContent(entry, xContentType, humanReadable);
        Entry<Option> parsed;
        try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
            ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
            parsed = ENTRY_PARSERS.get(entry.getClass()).apply(parser);
            assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
            assertNull(parser.nextToken());
        }
        assertEquals(entry.getClass(), parsed.getClass());
        assertEquals(entry.getText(), parsed.getText());
        assertEquals(entry.getLength(), parsed.getLength());
        assertEquals(entry.getOffset(), parsed.getOffset());
        assertEquals(entry.getOptions().size(), parsed.getOptions().size());
        for (int i = 0; i < entry.getOptions().size(); i++) {
            assertEquals(entry.getOptions().get(i).getClass(), parsed.getOptions().get(i).getClass());
        }
        assertToXContentEquivalent(originalBytes, toXContent(parsed, xContentType, humanReadable), xContentType);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:SuggestionEntryTests.java

示例14: testFromXContent

import org.elasticsearch.common.bytes.BytesReference; //导入依赖的package包/类
public void testFromXContent() throws IOException {
    ToXContent.Params params = new ToXContent.MapParams(Collections.singletonMap(RestSearchAction.TYPED_KEYS_PARAM, "true"));
    Suggest suggest = createTestItem();
    XContentType xContentType = randomFrom(XContentType.values());
    boolean humanReadable = randomBoolean();
    BytesReference originalBytes = toXContent(suggest, xContentType, params, humanReadable);
    Suggest parsed;
    try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
        ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
        ensureFieldName(parser, parser.nextToken(), Suggest.NAME);
        ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
        parsed = Suggest.fromXContent(parser);
        assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
        assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
        assertNull(parser.nextToken());
    }
    assertEquals(suggest.size(), parsed.size());
    for (Suggestion suggestion : suggest) {
        Suggestion<? extends Entry<? extends Option>> parsedSuggestion = parsed.getSuggestion(suggestion.getName());
        assertNotNull(parsedSuggestion);
        assertEquals(suggestion.getClass(), parsedSuggestion.getClass());
    }
    assertToXContentEquivalent(originalBytes, toXContent(parsed, xContentType, params, humanReadable), xContentType);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:SuggestTests.java

示例15: markStoreCorrupted

import org.elasticsearch.common.bytes.BytesReference; //导入依赖的package包/类
/**
 * Marks this store as corrupted. This method writes a <tt>corrupted_${uuid}</tt> file containing the given exception
 * message. If a store contains a <tt>corrupted_${uuid}</tt> file {@link #isMarkedCorrupted()} will return <code>true</code>.
 */
public void markStoreCorrupted(IOException exception) throws IOException {
    ensureOpen();
    if (!isMarkedCorrupted()) {
        String uuid = CORRUPTED + UUIDs.randomBase64UUID();
        try (IndexOutput output = this.directory().createOutput(uuid, IOContext.DEFAULT)) {
            CodecUtil.writeHeader(output, CODEC, VERSION);
            BytesStreamOutput out = new BytesStreamOutput();
            out.writeException(exception);
            BytesReference bytes = out.bytes();
            output.writeVInt(bytes.length());
            BytesRef ref = bytes.toBytesRef();
            output.writeBytes(ref.bytes, ref.offset, ref.length);
            CodecUtil.writeFooter(output);
        } catch (IOException ex) {
            logger.warn("Can't mark store as corrupted", ex);
        }
        directory().sync(Collections.singleton(uuid));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:Store.java


注:本文中的org.elasticsearch.common.bytes.BytesReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。