Package org.elasticsearch.hadoop.util

Examples of org.elasticsearch.hadoop.util.BytesArray


                else {
                    pool.get().bytes(val);
                }
            }
            else {
                BytesArray ba = pool.get();
                JacksonJsonGenerator generator = new JacksonJsonGenerator(new FastByteArrayOutputStream(ba));
                valueWriter.write(value, generator);
                generator.flush();
                generator.close();

                // jackson likely will add leading/trailing "" which are added down the pipeline so remove them
                // however that's not mandatory in case the source is a number (instead of a string)
                if ((lookForQuotes && !addQuotesIfNecessary) && ba.bytes()[ba.offset()] == '"') {
                    ba.size(Math.max(0, ba.length() - 2));
                    ba.offset(1);
                }
            }
        }
View Full Code Here


    @Override
    protected Object preProcess(Object object, BytesArray storage) {
        // serialize the json early on and copy it to storage
        Assert.notNull(object, "Empty/null JSON document given...");

        BytesArray ba = null;
        if (ConfigurationOptions.ES_OPERATION_UPSERT.equals(settings.getOperation())) {
            ba = storage;
        }
        else {
            scratchPad.reset();
View Full Code Here

        }
    }

    public static void putMapping(String index, byte[] content) throws Exception {
        RestClient rc = new ExtendedRestClient();
        BytesArray bs = new BytesArray(content);
        rc.putMapping(index, index + "/_mapping", bs.bytes());
        rc.close();
    }
View Full Code Here

    public void testEmptyBulkWrite() throws Exception {
        TestSettings testSettings = new TestSettings("rest/emptybulk");
        testSettings.setProperty(ConfigurationOptions.ES_SERIALIZATION_WRITER_VALUE_CLASS, JdkValueWriter.class.getName());
        RestRepository restRepo = new RestRepository(testSettings);
        RestClient client = restRepo.getRestClient();
        client.bulk(new Resource(testSettings, false), new TrackingBytesArray(new BytesArray("{}")));
        restRepo.waitForYellow();
        restRepo.close();
        client.close();
    }
View Full Code Here

        public String get(String index) throws IOException {
            return IOUtils.asString(execute(Request.Method.GET, index));
        }

        public String post(String index, byte[] buffer) throws IOException {
            return IOUtils.asString(execute(Request.Method.POST, index, new BytesArray(buffer)).body());
        }
View Full Code Here

        public String post(String index, byte[] buffer) throws IOException {
            return IOUtils.asString(execute(Request.Method.POST, index, new BytesArray(buffer)).body());
        }

        public String put(String index, byte[] buffer) throws IOException {
            return IOUtils.asString(execute(PUT, index, new BytesArray(buffer)).body());
        }
View Full Code Here

    }


    @Test
    public void testInvalidRequest() throws Exception {
        BytesArray be = new BytesArray("{\"index\":{\"_index\":\"mroldapi\",\"_type\":\"pattern-format-2179-10-06-with-id\"\"_id\":\"185\"}}" +
"{\"url\":\"http://www.last.fm/music/Reamonn\",\"@timestamp\":\"2179-10-06T19:20:25.000Z\",\"name\":\"Reamonn\",\"number\":\"185\",\"picture\":\"http://userserve-ak.last.fm/serve/252/45094837.png\"}");

        String error = "JsonParseException[Unexpected character ('\"' (code 34)): was expecting comma to separate OBJECT entries at [Source: [B@6e26dd20; line: 1, column: 75]]";

        assertEquals("0-06-with-id\"\"_id\":\"", ErrorUtils.extractJsonParse(error, be));
View Full Code Here

                    log.warn(String.format("No mapping found [%s] and no schema found; letting Elasticsearch perform auto-mapping...",  settings.getResourceWrite()));
                }
                else {
                    log.info(String.format("No mapping found [%s], creating one based on given schema", settings.getResourceWrite()));
                    ContentBuilder builder = ContentBuilder.generate(schemaWriter).value(schema).flush();
                    BytesArray content = ((FastByteArrayOutputStream) builder.content()).bytes();
                    builder.close();
                    client.putMapping(content);
                    if (log.isDebugEnabled()) {
                        log.debug(String.format("Creating ES mapping [%s] from schema [%s]", content.toString(), schema));
                    }
                }
            }
            client.close();
        }
View Full Code Here

        // NB: dynamically get the stats since the transport can change
        long start = network.transportStats().netTotalTime;
        try {
            // use post instead of get to avoid some weird encoding issues (caused by the long URL)
            InputStream is = execute(POST, "_search/scroll?scroll=" + scrollKeepAlive.toString(),
                    new BytesArray(scrollId.getBytes(StringUtils.UTF_8))).body();
            stats.scrollTotal++;
            return is;
        } finally {
            stats.scrollTotalTime += network.transportStats().netTotalTime - start;
        }
View Full Code Here

    public void putMapping(String index, String mapping, byte[] bytes) {
        // create index first (if needed) - it might return 403
        touch(index);

        execute(PUT, mapping, new BytesArray(bytes));
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.hadoop.util.BytesArray

Copyright © 2018 www.massapicom. 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.