Package org.elasticsearch.node

Examples of org.elasticsearch.node.Node


*/
public class GeoDistanceSearchBenchmark {

    public static void main(String[] args) throws Exception {

        Node node = NodeBuilder.nodeBuilder().clusterName(GeoDistanceSearchBenchmark.class.getSimpleName()).node();
        Client client = node.client();

        ClusterHealthResponse clusterHealthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
        if (clusterHealthResponse.isTimedOut()) {
            System.err.println("Failed to wait for green status, bailing");
            System.exit(1);
        }

        final long NUM_DOCS = SizeValue.parseSizeValue("1m").singles();
        final long NUM_WARM = 50;
        final long NUM_RUNS = 100;

        if (client.admin().indices().prepareExists("test").execute().actionGet().isExists()) {
            System.out.println("Found an index, count: " + client.prepareCount("test").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount());
        } else {
            String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                    .startObject("properties").startObject("location").field("type", "geo_point").field("lat_lon", true).endObject().endObject()
                    .endObject().endObject().string();
            client.admin().indices().prepareCreate("test")
                    .setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0))
                    .addMapping("type1", mapping)
                    .execute().actionGet();

            System.err.println("--> Indexing [" + NUM_DOCS + "]");
            for (long i = 0; i < NUM_DOCS; ) {
                client.prepareIndex("test", "type1", Long.toString(i++)).setSource(jsonBuilder().startObject()
                        .field("name", "New York")
                        .startObject("location").field("lat", 40.7143528).field("lon", -74.0059731).endObject()
                        .endObject()).execute().actionGet();

                // to NY: 5.286 km
                client.prepareIndex("test", "type1", Long.toString(i++)).setSource(jsonBuilder().startObject()
                        .field("name", "Times Square")
                        .startObject("location").field("lat", 40.759011).field("lon", -73.9844722).endObject()
                        .endObject()).execute().actionGet();

                // to NY: 0.4621 km
                client.prepareIndex("test", "type1", Long.toString(i++)).setSource(jsonBuilder().startObject()
                        .field("name", "Tribeca")
                        .startObject("location").field("lat", 40.718266).field("lon", -74.007819).endObject()
                        .endObject()).execute().actionGet();

                // to NY: 1.258 km
                client.prepareIndex("test", "type1", Long.toString(i++)).setSource(jsonBuilder().startObject()
                        .field("name", "Soho")
                        .startObject("location").field("lat", 40.7247222).field("lon", -74).endObject()
                        .endObject()).execute().actionGet();

                // to NY: 8.572 km
                client.prepareIndex("test", "type1", Long.toString(i++)).setSource(jsonBuilder().startObject()
                        .field("name", "Brooklyn")
                        .startObject("location").field("lat", 40.65).field("lon", -73.95).endObject()
                        .endObject()).execute().actionGet();

                if ((i % 10000) == 0) {
                    System.err.println("--> indexed " + i);
                }
            }
            System.err.println("Done indexed");
            client.admin().indices().prepareFlush("test").execute().actionGet();
            client.admin().indices().prepareRefresh().execute().actionGet();
        }

        System.err.println("--> Warming up (ARC) - optimize_bbox");
        long start = System.currentTimeMillis();
        for (int i = 0; i < NUM_WARM; i++) {
            run(client, GeoDistance.ARC, "memory");
        }
        long totalTime = System.currentTimeMillis() - start;
        System.err.println("--> Warmup (ARC)  - optimize_bbox (memory) " + (totalTime / NUM_WARM) + "ms");

        System.err.println("--> Perf (ARC) - optimize_bbox (memory)");
        start = System.currentTimeMillis();
        for (int i = 0; i < NUM_RUNS; i++) {
            run(client, GeoDistance.ARC, "memory");
        }
        totalTime = System.currentTimeMillis() - start;
        System.err.println("--> Perf (ARC) - optimize_bbox " + (totalTime / NUM_RUNS) + "ms");

        System.err.println("--> Warming up (ARC)  - optimize_bbox (indexed)");
        start = System.currentTimeMillis();
        for (int i = 0; i < NUM_WARM; i++) {
            run(client, GeoDistance.ARC, "indexed");
        }
        totalTime = System.currentTimeMillis() - start;
        System.err.println("--> Warmup (ARC) - optimize_bbox (indexed) " + (totalTime / NUM_WARM) + "ms");

        System.err.println("--> Perf (ARC) - optimize_bbox (indexed)");
        start = System.currentTimeMillis();
        for (int i = 0; i < NUM_RUNS; i++) {
            run(client, GeoDistance.ARC, "indexed");
        }
        totalTime = System.currentTimeMillis() - start;
        System.err.println("--> Perf (ARC) - optimize_bbox (indexed) " + (totalTime / NUM_RUNS) + "ms");


        System.err.println("--> Warming up (ARC)  - no optimize_bbox");
        start = System.currentTimeMillis();
        for (int i = 0; i < NUM_WARM; i++) {
            run(client, GeoDistance.ARC, "none");
        }
        totalTime = System.currentTimeMillis() - start;
        System.err.println("--> Warmup (ARC) - no optimize_bbox " + (totalTime / NUM_WARM) + "ms");

        System.err.println("--> Perf (ARC) - no optimize_bbox");
        start = System.currentTimeMillis();
        for (int i = 0; i < NUM_RUNS; i++) {
            run(client, GeoDistance.ARC, "none");
        }
        totalTime = System.currentTimeMillis() - start;
        System.err.println("--> Perf (ARC) - no optimize_bbox " + (totalTime / NUM_RUNS) + "ms");

        System.err.println("--> Warming up (SLOPPY_ARC)");
        start = System.currentTimeMillis();
        for (int i = 0; i < NUM_WARM; i++) {
            run(client, GeoDistance.SLOPPY_ARC, "memory");
        }
        totalTime = System.currentTimeMillis() - start;
        System.err.println("--> Warmup (SLOPPY_ARC) " + (totalTime / NUM_WARM) + "ms");

        System.err.println("--> Perf (SLOPPY_ARC)");
        start = System.currentTimeMillis();
        for (int i = 0; i < NUM_RUNS; i++) {
            run(client, GeoDistance.SLOPPY_ARC, "memory");
        }
        totalTime = System.currentTimeMillis() - start;
        System.err.println("--> Perf (SLOPPY_ARC) " + (totalTime / NUM_RUNS) + "ms");

        System.err.println("--> Warming up (PLANE)");
        start = System.currentTimeMillis();
        for (int i = 0; i < NUM_WARM; i++) {
            run(client, GeoDistance.PLANE, "memory");
        }
        totalTime = System.currentTimeMillis() - start;
        System.err.println("--> Warmup (PLANE) " + (totalTime / NUM_WARM) + "ms");

        System.err.println("--> Perf (PLANE)");
        start = System.currentTimeMillis();
        for (int i = 0; i < NUM_RUNS; i++) {
            run(client, GeoDistance.PLANE, "memory");
        }
        totalTime = System.currentTimeMillis() - start;
        System.err.println("--> Perf (PLANE) " + (totalTime / NUM_RUNS) + "ms");

        node.close();
    }
View Full Code Here


    @Test
    public void testNodeVersionIsUpdated() {
        TransportClient client = (TransportClientinternalCluster().client();
        TransportClientNodesService nodeService = client.nodeService();
        Node node = nodeBuilder().data(false).settings(ImmutableSettings.builder()
                .put(internalCluster().getDefaultSettings())
                .put("node.name", "testNodeVersionIsUpdated")
                .put("http.enabled", false)
                .put("index.store.type", "ram")
                .put("config.ignore_system_properties", true) // make sure we get what we set :)
                .put("gateway.type", "none")
                .build()).clusterName("foobar").build();
        node.start();
        try {
            TransportAddress transportAddress = ((InternalNode) node).injector().getInstance(TransportService.class).boundAddress().publishAddress();
            client.addTransportAddress(transportAddress);
            assertThat(nodeService.connectedNodes().size(), greaterThanOrEqualTo(1)); // since we force transport clients there has to be one node started that we connect to.
            for (DiscoveryNode discoveryNode : nodeService.connectedNodes()) {  // connected nodes have updated version
                assertThat(discoveryNode.getVersion(), equalTo(Version.CURRENT));
            }

            for (DiscoveryNode discoveryNode : nodeService.listedNodes()) {
                assertThat(discoveryNode.id(), startsWith("#transport#-"));
                assertThat(discoveryNode.getVersion(), equalTo(Version.CURRENT.minimumCompatibilityVersion()));
            }

            assertThat(nodeService.filteredNodes().size(), equalTo(1));
            for (DiscoveryNode discoveryNode : nodeService.filteredNodes()) {
                assertThat(discoveryNode.getVersion(), equalTo(Version.CURRENT.minimumCompatibilityVersion()));
            }
        } finally {
            node.close();
        }
    }
View Full Code Here

                .put("gateway.type", "local")
                .put(SETTING_NUMBER_OF_SHARDS, 1)
                .put(SETTING_NUMBER_OF_REPLICAS, 0)
                .build();

        Node node1 = nodeBuilder()
                .settings(settingsBuilder().put(settings).put("name", "node1"))
                .node();
        Client client = node1.client();

        int count = (int) SizeValue.parseSizeValue("1m").singles();
        int nestedCount = 10;
        int rootDocs = count / nestedCount;
        int batch = 100;
View Full Code Here

                .put(SETTING_NUMBER_OF_SHARDS, 1)
                .put(SETTING_NUMBER_OF_REPLICAS, 0)
                .build();

        String clusterName = ChildSearchShortCircuitBenchmark.class.getSimpleName();
        Node node1 = nodeBuilder().clusterName(clusterName)
                .settings(settingsBuilder().put(settings).put("name", "node1"))
                .node();
        Client client = node1.client();

        long PARENT_COUNT = SizeValue.parseSizeValue("10M").singles();
        int BATCH = 100;
        int QUERY_WARMUP = 5;
        int QUERY_COUNT = 25;
        String indexName = "test";

        client.admin().cluster().prepareHealth(indexName).setWaitForGreenStatus().setTimeout("10s").execute().actionGet();
        try {
            client.admin().indices().create(createIndexRequest(indexName)).actionGet();
            client.admin().indices().preparePutMapping(indexName).setType("child").setSource(XContentFactory.jsonBuilder().startObject().startObject("child")
                    .startObject("_parent").field("type", "parent").endObject()
                    .endObject().endObject()).execute().actionGet();
            Thread.sleep(5000);

            StopWatch stopWatch = new StopWatch().start();

            System.out.println("--> Indexing [" + PARENT_COUNT + "] parent document and some child documents");
            long ITERS = PARENT_COUNT / BATCH;
            int i = 1;
            int counter = 0;
            for (; i <= ITERS; i++) {
                BulkRequestBuilder request = client.prepareBulk();
                for (int j = 0; j < BATCH; j++) {
                    counter++;
                    request.add(Requests.indexRequest(indexName).type("parent").id(Integer.toString(counter))
                            .source(parentSource(counter)));

                }
                BulkResponse response = request.execute().actionGet();
                if (response.hasFailures()) {
                    System.err.println("--> failures...");
                }
                if (((i * BATCH) % 10000) == 0) {
                    System.out.println("--> Indexed " + (i * BATCH) + "parent docs; took " + stopWatch.stop().lastTaskTime());
                    stopWatch.start();
                }
            }

            int id = 0;
            for (i = 1; i <= PARENT_COUNT; i *= 2) {
                int parentId = 1;
                for (int j = 0; j < i; j++) {
                    client.prepareIndex(indexName, "child", Integer.toString(id++))
                            .setParent(Integer.toString(parentId++))
                            .setSource(childSource(i))
                            .execute().actionGet();
                }
            }

            System.out.println("--> Indexing took " + stopWatch.totalTime());
        } catch (Exception e) {
            System.out.println("--> Index already exists, ignoring indexing phase, waiting for green");
            ClusterHealthResponse clusterHealthResponse = client.admin().cluster().prepareHealth(indexName).setWaitForGreenStatus().setTimeout("10m").execute().actionGet();
            if (clusterHealthResponse.isTimedOut()) {
                System.err.println("--> Timed out waiting for cluster health");
            }
        }
        client.admin().indices().prepareRefresh().execute().actionGet();
        System.out.println("--> Number of docs in index: " + client.prepareCount(indexName).setQuery(matchAllQuery()).execute().actionGet().getCount());

        System.out.println("--> Running just child query");
        // run just the child query, warm up first
        for (int i = 1; i <= 10000; i *= 2) {
            SearchResponse searchResponse = client.prepareSearch(indexName).setQuery(matchQuery("child.field2", i)).execute().actionGet();
            System.out.println("--> Warmup took["+ i +"]: " + searchResponse.getTook());
            if (searchResponse.getHits().totalHits() != i) {
                System.err.println("--> mismatch on hits");
            }
        }

        NodesStatsResponse statsResponse = client.admin().cluster().prepareNodesStats()
                .setJvm(true).execute().actionGet();
        System.out.println("--> Committed heap size: " + statsResponse.getNodes()[0].getJvm().getMem().getHeapCommitted());
        System.out.println("--> Used heap size: " + statsResponse.getNodes()[0].getJvm().getMem().getHeapUsed());

        // run parent child constant query
        for (int j = 1; j < QUERY_WARMUP; j *= 2) {
            SearchResponse searchResponse = client.prepareSearch(indexName)
                    .setQuery(
                            hasChildQuery("child", matchQuery("field2", j))
                    )
                    .execute().actionGet();
            if (searchResponse.getFailedShards() > 0) {
                System.err.println("Search Failures " + Arrays.toString(searchResponse.getShardFailures()));
            }
            if (searchResponse.getHits().totalHits() != j) {
                System.err.println("--> mismatch on hits [" + j + "], got [" + searchResponse.getHits().totalHits() + "], expected [" + PARENT_COUNT + "]");
            }
        }

        long totalQueryTime = 0;
        for (int i = 1; i < PARENT_COUNT; i *= 2) {
            for (int j = 0; j < QUERY_COUNT; j++) {
                SearchResponse searchResponse = client.prepareSearch(indexName)
                        .setQuery(filteredQuery(matchAllQuery(), hasChildFilter("child", matchQuery("field2", i))))
                        .execute().actionGet();
                if (searchResponse.getHits().totalHits() != i) {
                    System.err.println("--> mismatch on hits");
                }
                totalQueryTime += searchResponse.getTookInMillis();
            }
            System.out.println("--> has_child filter " + i +" Avg: " + (totalQueryTime / QUERY_COUNT) + "ms");
        }

        statsResponse = client.admin().cluster().prepareNodesStats()
                .setJvm(true).setIndices(true).execute().actionGet();

        System.out.println("--> Id cache size: " + statsResponse.getNodes()[0].getIndices().getIdCache().getMemorySize());
        System.out.println("--> Used heap size: " + statsResponse.getNodes()[0].getJvm().getMem().getHeapUsed());

        totalQueryTime = 0;
        for (int i = 1; i < PARENT_COUNT; i *= 2) {
            for (int j = 0; j < QUERY_COUNT; j++) {
                SearchResponse searchResponse = client.prepareSearch(indexName)
                        .setQuery(hasChildQuery("child", matchQuery("field2", i)).scoreType("max"))
                        .execute().actionGet();
                if (searchResponse.getHits().totalHits() != i) {
                    System.err.println("--> mismatch on hits");
                }
                totalQueryTime += searchResponse.getTookInMillis();
            }
            System.out.println("--> has_child query " + i +" Avg: " + (totalQueryTime / QUERY_COUNT) + "ms");
        }

        System.gc();
        statsResponse = client.admin().cluster().prepareNodesStats()
                .setJvm(true).setIndices(true).execute().actionGet();

        System.out.println("--> Id cache size: " + statsResponse.getNodes()[0].getIndices().getIdCache().getMemorySize());
        System.out.println("--> Used heap size: " + statsResponse.getNodes()[0].getJvm().getMem().getHeapUsed());

        client.close();
        node1.close();
    }
View Full Code Here

                .put(SETTING_NUMBER_OF_SHARDS, 1)
                .put(SETTING_NUMBER_OF_REPLICAS, 0)
                .build();

        String clusterName = ChildSearchAndIndexingBenchmark.class.getSimpleName();
        Node node1 = nodeBuilder().settings(settingsBuilder().put(settings).put("name", "node1"))
                .clusterName(clusterName)
                .node();
        Client client = node1.client();

        client.admin().cluster().prepareHealth(indexName).setWaitForGreenStatus().setTimeout("10s").execute().actionGet();
        try {
            client.admin().indices().create(createIndexRequest(indexName)).actionGet();
            client.admin().indices().preparePutMapping(indexName).setType("child").setSource(XContentFactory.jsonBuilder().startObject().startObject("child")
                    .startObject("_parent").field("type", "parent").endObject()
                    .endObject().endObject()).execute().actionGet();
            Thread.sleep(5000);

            long startTime = System.currentTimeMillis();
            ParentChildIndexGenerator generator = new ParentChildIndexGenerator(client, PARENT_COUNT, NUM_CHILDREN_PER_PARENT, QUERY_VALUE_RATIO_PER_PARENT);
            generator.index();
            System.out.println("--> Indexing took " + ((System.currentTimeMillis() - startTime) / 1000) + " seconds.");
        } catch (IndexAlreadyExistsException e) {
            System.out.println("--> Index already exists, ignoring indexing phase, waiting for green");
            ClusterHealthResponse clusterHealthResponse = client.admin().cluster().prepareHealth(indexName).setWaitForGreenStatus().setTimeout("10m").execute().actionGet();
            if (clusterHealthResponse.isTimedOut()) {
                System.err.println("--> Timed out waiting for cluster health");
            }
        }
        client.admin().indices().prepareRefresh().execute().actionGet();
        System.out.println("--> Number of docs in index: " + client.prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount());

        SearchThread searchThread = new SearchThread(client);
        new Thread(searchThread).start();
        IndexThread indexThread = new IndexThread(client);
        new Thread(indexThread).start();

        System.in.read();

        indexThread.stop();
        searchThread.stop();
        client.close();
        node1.close();
    }
View Full Code Here

            nodes[i] = nodeBuilder().clusterName(CLUSTER_NAME)
                    .settings(settingsBuilder().put(settings).put("name", "node" + i))
                    .node();
        }

        Node clientNode = nodeBuilder()
                .clusterName(CLUSTER_NAME)
                .settings(settingsBuilder().put(settings).put("name", "client")).client(true).node();

        Client client = clientNode.client();

        for (Distribution d : Distribution.values()) {
            try {
//                client.admin().indices().prepareDelete(d.indexName()).execute().actionGet();
                client.admin().indices().create(createIndexRequest(d.indexName()).settings(settings)).actionGet();
View Full Code Here

                .put(SETTING_NUMBER_OF_SHARDS, 2)
                .put(SETTING_NUMBER_OF_REPLICAS, 0)
                .build();

        String clusterName = QueryFilterAggregationSearchBenchmark.class.getSimpleName();
        Node node1 = nodeBuilder()
                .clusterName(clusterName)
                .settings(settingsBuilder().put(settings).put("name", "node1")).node();
        client = node1.client();

        long[] lValues = new long[NUMBER_OF_TERMS];
        for (int i = 0; i < NUMBER_OF_TERMS; i++) {
            lValues[i] = ThreadLocalRandom.current().nextLong();
        }
View Full Code Here

* Just launch it and add files to scan in /tmp/tmp_es dir
*/
public class StandAloneRunner {

    public static void main(String[] args) {
        Node node = null;
        try {
            // Remove old data
            FileSystemUtils.deleteRecursively(new File("./target/data"));

            node = NodeBuilder.nodeBuilder().settings(
                    ImmutableSettings.builder().put("path.data", "./target/data").build()
            ).node();

            XContentBuilder river = jsonBuilder().prettyPrint().startObject()
                    .field("type", "fs")
                    .startObject("fs")
                    .field("url", "/tmp/tmp_es")
                    .field("update_rate", 500)
                    .endObject()
                    .startObject("index")
                    .field("bulk_size", 1)
                    .endObject()
                    .endObject();

            System.out.println("Startin river");
            System.out.println(river.string());
            node.client().prepareIndex("_river", "main_fs", "_meta").setSource(river).execute().actionGet();

            // Waiting for kill signal
            System.out.print("press return when finished:");
            System.in.read();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (node != null) {
                node.close();
            }
        }
    }
View Full Code Here

* http://localhost:8983/_plugin/main
*/
public class StartLocalNode {
    public static void main(String[] args) throws Exception {
        System.setProperty("log4j.configuration", "log4j-verbose.properties");
        Node node = nodeBuilder().settings(settingsBuilder()
                .put("path.data", "target/data")
                .put("path.plugins", "src")
                .put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress()))
                .local(false)
                .node();

        node.start();

        new CountDownLatch(1).await();
    }
View Full Code Here

        }
        if (finalSettings.get("cluster.routing.schedule") != null) {
            // decrease the routing schedule so new nodes will be added quickly
            finalSettings = settingsBuilder().put(finalSettings).put("cluster.routing.schedule", "50ms").build();
        }
        Node node = nodeBuilder().settings(finalSettings).build();

        Client client = node.client();

        nodes.put(id, node);
        clients.put(id, client);
        return node;
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.node.Node

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.