Package org.elasticsearch.action.search

Examples of org.elasticsearch.action.search.SearchResponse$Fields


    logger.debug("go to delete indexed issues for space {} not updated after {}", spaceKey, boundDate);
    SearchRequestBuilder srb = esIntegrationComponent.prepareESScrollSearchRequestBuilder(indexName);
    documentIndexStructureBuilder.buildSearchForIndexedDocumentsNotUpdatedAfter(srb, spaceKey, boundDate);

    SearchResponse scrollResp = esIntegrationComponent.executeESSearchRequest(srb);

    if (scrollResp.getHits().getTotalHits() > 0) {
      if (isClosed())
        throw new InterruptedException("Interrupted because River is closed");
      scrollResp = esIntegrationComponent.executeESScrollSearchNextRequest(scrollResp);
      BulkRequestBuilder esBulk = esIntegrationComponent.prepareESBulkRequestBuilder();
      while (scrollResp.getHits().getHits().length > 0) {
        for (SearchHit hit : scrollResp.getHits()) {
          logger.debug("Go to delete indexed document for ES document id {}", hit.getId());
          if (documentIndexStructureBuilder.deleteESDocument(esBulk, hit)) {
            indexingInfo.documentsDeleted++;
          } else {
            indexingInfo.commentsDeleted++;
View Full Code Here


        System.out.println("--> Number of docs in index: " + client.prepareCount().setQuery(matchAllQuery()).execute().actionGet().count());

        System.out.println("--> Running just child query");
        // run just the child query, warm up first
        for (int j = 0; j < QUERY_WARMUP; j++) {
            SearchResponse searchResponse = client.prepareSearch().setQuery(termQuery("child.tag", "tag1")).execute().actionGet();
            if (j == 0) {
                System.out.println("--> Warmup took: " + searchResponse.took());
            }
            if (searchResponse.hits().totalHits() != COUNT) {
                System.err.println("--> mismatch on hits");
            }
        }

        long totalQueryTime = 0;
        for (int j = 0; j < QUERY_COUNT; j++) {
            SearchResponse searchResponse = client.prepareSearch().setQuery(termQuery("child.tag", "tag1")).execute().actionGet();
            if (searchResponse.hits().totalHits() != COUNT) {
                System.err.println("--> mismatch on hits");
            }
            totalQueryTime += searchResponse.tookInMillis();
        }
        System.out.println("--> Just Child Query Avg: " + (totalQueryTime / QUERY_COUNT) + "ms");

        System.out.println("--> Running has_child query");
        // run parent child constant query
        for (int j = 0; j < QUERY_WARMUP; j++) {
            SearchResponse searchResponse = client.prepareSearch().setQuery(hasChildQuery("child", termQuery("tag", "tag1"))).execute().actionGet();
            if (searchResponse.failedShards() > 0) {
                System.err.println("Search Failures " + Arrays.toString(searchResponse.shardFailures()));
            }
            if (searchResponse.hits().totalHits() != COUNT) {
                System.err.println("--> mismatch on hits [" + j + "], got [" + searchResponse.hits().totalHits() + "], expected [" + COUNT + "]");
            }
        }

        totalQueryTime = 0;
        for (int j = 0; j < QUERY_COUNT; j++) {
            SearchResponse searchResponse = client.prepareSearch().setQuery(hasChildQuery("child", termQuery("tag", "tag1"))).execute().actionGet();
            if (searchResponse.failedShards() > 0) {
                System.err.println("Search Failures " + Arrays.toString(searchResponse.shardFailures()));
            }
            if (searchResponse.hits().totalHits() != COUNT) {
                System.err.println("--> mismatch on hits [" + j + "], got [" + searchResponse.hits().totalHits() + "], expected [" + COUNT + "]");
            }
            totalQueryTime += searchResponse.tookInMillis();
        }
        System.out.println("--> has_child Query Avg: " + (totalQueryTime / QUERY_COUNT) + "ms");

        System.out.println("--> Running top_children query");
        // run parent child score query
        for (int j = 0; j < QUERY_WARMUP; j++) {
            SearchResponse searchResponse = client.prepareSearch().setQuery(topChildrenQuery("child", termQuery("tag", "tag1"))).execute().actionGet();
            // we expect to have mismatch on hits here
//            if (searchResponse.hits().totalHits() != COUNT) {
//                System.err.println("mismatch on hits");
//            }
        }

        totalQueryTime = 0;
        for (int j = 0; j < QUERY_COUNT; j++) {
            SearchResponse searchResponse = client.prepareSearch().setQuery(topChildrenQuery("child", termQuery("tag", "tag1"))).execute().actionGet();
            // we expect to have mismatch on hits here
//            if (searchResponse.hits().totalHits() != COUNT) {
//                System.err.println("mismatch on hits");
//            }
            totalQueryTime += searchResponse.tookInMillis();
        }
        System.out.println("--> top_children Query Avg: " + (totalQueryTime / QUERY_COUNT) + "ms");

        clientNode.close();
View Full Code Here

                for (; counter < max; counter++) {
                    Client client = client(counter);
                    QueryBuilder query = termQuery("num", counter % fieldNumLimit);
                    query = constantScoreQuery(queryFilter(query));

                    SearchResponse search = client.search(searchRequest()
                            .source(searchSource().query(query)))
                            .actionGet();
//                    System.out.println("Got search response, hits [" + search.hits().totalHits() + "]");
                }
            } catch (Exception e) {
View Full Code Here

     */
    public List<String> executeSearch(String source) {
        SearchRequest request = Requests.searchRequest(INDEX_NAME).source(source);

        List<ShardSearchFailure> failures;
        SearchResponse response;

        response = client.search(request).actionGet();
        failures = Arrays.asList(response.getShardFailures());

        // throw an exception so that we see the shard failures
        if (failures.size() != 0) {
            String failuresStr = failures.toString();
            if (!failuresStr.contains("reason [No active shards]")) {
                throw new RuntimeException(failures.toString());
            }
        }

        ArrayList<String> results = new ArrayList<String>();
        if (response != null) {
            for (SearchHit hit : response.hits()) {
                String sourceStr = hit.sourceAsString();
                results.add(sourceStr);
            }
        }
        return results;
View Full Code Here

                logger.warn("count does not match!");
            }
        }

        // scan all the docs, verify all have the same version based on the number of replicas
        SearchResponse searchResponse = client.client().prepareSearch()
                .setSearchType(SearchType.SCAN)
                .setQuery(matchAllQuery())
                .setSize(50)
                .setScroll(TimeValue.timeValueMinutes(2))
                .execute().actionGet();
        logger.info("Verifying versions for {} hits...", searchResponse.hits().totalHits());

        while (true) {
            searchResponse = client.client().prepareSearchScroll(searchResponse.scrollId()).setScroll(TimeValue.timeValueMinutes(2)).execute().actionGet();
            if (searchResponse.failedShards() > 0) {
                logger.warn("Search Failures " + Arrays.toString(searchResponse.shardFailures()));
            }
            for (SearchHit hit : searchResponse.hits()) {
                long version = -1;
                for (int i = 0; i < (numberOfReplicas + 1); i++) {
                    GetResponse getResponse = client.client().prepareGet(hit.index(), hit.type(), hit.id()).execute().actionGet();
                    if (version == -1) {
                        version = getResponse.version();
                    } else {
                        if (version != getResponse.version()) {
                            logger.warn("Doc {} has different version numbers {} and {}", hit.id(), version, getResponse.version());
                        }
                    }
                }
            }
            if (searchResponse.hits().hits().length == 0) {
                break;
            }
        }
        logger.info("Done verifying versions");
View Full Code Here

        System.out.println("done indexing, verifying docs");
        client.client().admin().indices().prepareRefresh().execute().actionGet();
        for (int i = 0; i < NUMBER_OF_DOCS; i++) {
            String id = Integer.toString(i);
            for (int j = 0; j < 5; j++) {
                SearchResponse response = client.client().prepareSearch().setQuery(QueryBuilders.termQuery("_id", id)).execute().actionGet();
                if (response.hits().totalHits() > 1) {
                    System.err.println("[" + i + "] FAIL, HITS [" + response.hits().totalHits() + "]");
                }
            }
            GetResponse getResponse = client.client().prepareGet("test", "type1", id).execute().actionGet();
            if (getResponse.exists()) {
                long version = getResponse.version();
View Full Code Here

                        builder.setFrom(size / 2);
                    }
                    String value = nextFieldValue();
                    builder.setQuery(termQuery("field", value));
                    searchCounter.incrementAndGet();
                    SearchResponse searchResponse = builder.execute().actionGet();
                    if (searchResponse.failedShards() > 0) {
                        logger.warn("failed search " + Arrays.toString(searchResponse.shardFailures()));
                    }
                    // verify that all come from the requested index
                    for (SearchHit hit : searchResponse.hits()) {
                        if (!hit.shard().index().equals(indexName)) {
                            logger.warn("got wrong index, asked for [{}], got [{}]", indexName, hit.shard().index());
                        }
                    }
                    // verify that all has the relevant value
                    for (SearchHit hit : searchResponse.hits()) {
                        if (!value.equals(hit.sourceAsMap().get("field"))) {
                            logger.warn("got wrong field, asked for [{}], got [{}]", value, hit.sourceAsMap().get("field"));
                        }
                    }
                    Thread.sleep(searcherThrottle.millis());
View Full Code Here

            }

            // verify search
            for (int i = 0; i < (nodes.length * 5); i++) {
                // do a search with norms field, so we don't rely on match all filtering cache
                SearchResponse search = client.client().prepareSearch().setQuery(matchAllQuery().normsField("field")).execute().actionGet();
                logger.debug("index_count [{}], expected_count [{}]", search.hits().totalHits(), indexCounter.get());
                if (count.count() != indexCounter.get()) {
                    logger.warn("!!! search does not match, index_count [{}], expected_count [{}]", search.hits().totalHits(), indexCounter.get());
                    throw new Exception("failed test, count does not match...");
                }
            }

            logger.info("*** ROUND {}", ++numberOfRounds);
View Full Code Here

                .startObject("location").field("lat", 40.65).field("lon", -73.95).endObject()
                .endObject()).execute().actionGet();

        client.admin().indices().prepareRefresh().execute().actionGet();

        SearchResponse searchResponse = client.prepareSearch() // from NY
                .setQuery(filteredQuery(matchAllQuery(), geoBoundingBoxFilter("location").topLeft(40.73, -74.1).bottomRight(40.717, -73.99)))
                .execute().actionGet();
        assertThat(searchResponse.hits().getTotalHits(), equalTo(2l));
        assertThat(searchResponse.hits().hits().length, equalTo(2));
        for (SearchHit hit : searchResponse.hits()) {
            System.err.println("-->" + hit.id());
            assertThat(hit.id(), anyOf(equalTo("1"), equalTo("3"), equalTo("5")));
        }
    }
View Full Code Here

                .startObject("location").field("lat", -10).field("lon", 170).endObject()
                .endObject()).execute().actionGet();

        client.admin().indices().prepareRefresh().execute().actionGet();

        SearchResponse searchResponse = client.prepareSearch()
                .setQuery(filteredQuery(matchAllQuery(), geoBoundingBoxFilter("location").topLeft(41, -11).bottomRight(40, 9)))
                .execute().actionGet();
        assertThat(searchResponse.hits().getTotalHits(), equalTo(1l));
        assertThat(searchResponse.hits().hits().length, equalTo(1));
        assertThat(searchResponse.hits().getAt(0).id(), equalTo("2"));

        searchResponse = client.prepareSearch()
                .setQuery(filteredQuery(matchAllQuery(), geoBoundingBoxFilter("location").topLeft(41, -9).bottomRight(40, 11)))
                .execute().actionGet();
        assertThat(searchResponse.hits().getTotalHits(), equalTo(1l));
        assertThat(searchResponse.hits().hits().length, equalTo(1));
        assertThat(searchResponse.hits().getAt(0).id(), equalTo("3"));

        searchResponse = client.prepareSearch()
                .setQuery(filteredQuery(matchAllQuery(), geoBoundingBoxFilter("location").topLeft(11, 171).bottomRight(1, -169)))
                .execute().actionGet();
        assertThat(searchResponse.hits().getTotalHits(), equalTo(1l));
        assertThat(searchResponse.hits().hits().length, equalTo(1));
        assertThat(searchResponse.hits().getAt(0).id(), equalTo("5"));

        searchResponse = client.prepareSearch()
                .setQuery(filteredQuery(matchAllQuery(), geoBoundingBoxFilter("location").topLeft(9, 169).bottomRight(-1, -171)))
                .execute().actionGet();
        assertThat(searchResponse.hits().getTotalHits(), equalTo(1l));
        assertThat(searchResponse.hits().hits().length, equalTo(1));
        assertThat(searchResponse.hits().getAt(0).id(), equalTo("9"));
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.search.SearchResponse$Fields

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.