Package org.elasticsearch.search

Examples of org.elasticsearch.search.SearchHit


        SearchResponse sr = client.prepareSearch(activityLogIndexName).setTypes(activityLogTypeName)
            .setPostFilter(FilterBuilders.termFilter(ProjectIndexingInfo.DOCFIELD_PROJECT_KEY, projectKey))
            .setQuery(QueryBuilders.matchAllQuery()).addSort(ProjectIndexingInfo.DOCFIELD_START_DATE, SortOrder.DESC)
            .addField("_source").setSize(1).execute().actionGet();
        if (sr.getHits().getTotalHits() > 0) {
          SearchHit hit = sr.getHits().getAt(0);
          lastIndexing = ProjectIndexingInfo.readFromDocument(hit.sourceAsMap());
        } else {
          logger.debug("No last indexing info found in activity log for project {}", projectKey);
        }
      } catch (Exception e) {
        logger.warn("Error during LastProjectIndexingInfo reading from activity log ES index: {} {}", e.getClass()
View Full Code Here


                            SortBuilders.fieldSort(LAST_MODIFIED).order(
                                    SortOrder.DESC)).setFrom(0).setSize(1)
                    .execute().actionGet();
            final SearchHits hits = response.getHits();
            if (hits.getTotalHits() > 0) {
                final SearchHit hit = hits.getHits()[0];
                final Map<String, Object> sourceMap = hit.getSource();
                final Date date = (Date) sourceMap.get(LAST_MODIFIED);
                if (date != null) {
                    urlQueue.setLastModified(new Timestamp(date.getTime()));
                }
            }
View Full Code Here

        SearchResponse sr = client.prepareSearch(activityLogIndexName).setTypes(activityLogTypeName)
            .setFilter(FilterBuilders.termFilter(SpaceIndexingInfo.DOCFIELD_SPACE_KEY, spaceKey))
            .setQuery(QueryBuilders.matchAllQuery()).addSort(SpaceIndexingInfo.DOCFIELD_START_DATE, SortOrder.DESC)
            .addField("_source").setSize(1).execute().actionGet();
        if (sr.getHits().getTotalHits() > 0) {
          SearchHit hit = sr.getHits().getAt(0);
          lastIndexing = SpaceIndexingInfo.readFromDocument(hit.sourceAsMap());
        } else {
          logger.debug("No last indexing info found in activity log for space {}", spaceKey);
        }
      } catch (Exception e) {
        logger.warn("Error during LastSpaceIndexingInfo reading from activity log ES index: {} {}", e.getClass()
View Full Code Here

        SearchResponse sr = client.prepareSearch(activityLogIndexName).setTypes(activityLogTypeName)
            .setFilter(FilterBuilders.termFilter(SpaceIndexingInfo.DOCFIELD_SPACE_KEY, spaceKey))
            .setQuery(QueryBuilders.matchAllQuery()).addSort(SpaceIndexingInfo.DOCFIELD_START_DATE, SortOrder.DESC)
            .addField("_source").setSize(1).execute().actionGet();
        if (sr.getHits().getTotalHits() > 0) {
          SearchHit hit = sr.getHits().getAt(0);
          lastIndexing = SpaceIndexingInfo.readFromDocument(hit.sourceAsMap());
        } else {
          logger.debug("No last indexing info found in activity log for space {}", spaceKey);
        }
      } catch (Exception e) {
        logger.warn("Error during LastSpaceIndexingInfo reading from activity log ES index: {} {}", e.getClass()
View Full Code Here

              logger.debug(message);
              if (ignoreMultipleResults) {
                continue;
              }
            }
            SearchHit hit = resp.getHits().hits()[0];
            for (Map<String, String> mappingRecord : resultMapping) {
              String idx_resultField = mappingRecord.get(CFG_idx_result_field);
              Object v = null;
              SearchHitField shf = null;
              if ("_source".equals(idx_resultField)) {
                v = hit.getSource();
              } else {
                shf = hit.field(idx_resultField);
                if (shf != null) {
                  v = shf.getValue();
                }
              }
              if (shf != null || v != null) {
View Full Code Here

    assertThat(result.getModel(), is("Grat"));
    assertThat(result.getName(), is("Ford"));
  }

  private SearchHit createCarHit(String name, String model) {
    SearchHit hit = mock(SearchHit.class);
    when(hit.sourceAsString()).thenReturn(createJsonCar(name, model));
    return hit;
  }
View Full Code Here

    when(hit.sourceAsString()).thenReturn(createJsonCar(name, model));
    return hit;
  }

  private SearchHit createCarPartialHit(String name, String model) {
    SearchHit hit = mock(SearchHit.class);
    when(hit.sourceAsString()).thenReturn(null);
    when(hit.getFields()).thenReturn(createCarFields(name, model));
    return hit;
  }
View Full Code Here

                .addField("_id")
                .setSize(nbOfResultsToCheck)
                .get();

        for (int i=0; i < Math.min(response.getHits().getTotalHits(), nbOfResultsToCheck); i++) {
            SearchHit hit = response.getHits().getAt(i);
            int docId = Integer.parseInt(hit.getId());

            assertThat(hit.field("foo"), notNullValue());
            assertThat(hit.field("foo").getValue().toString(), is("bar"));
            assertThat(hit.field("_id"), nullValue());
            if ((docId % 2) == 0) {
                assertThat(hit.field("content"), nullValue());
            } else {
                assertThat(hit.field("content").getValue().toString(), is(hit.getId()));
            }
        }
    }
View Full Code Here

      .setTypes(this.getIndexType())
      .setQuery(QueryBuilders.termQuery(RuleNormalizer.RuleField.ID.field(), id))
      .setSize(1);
    SearchResponse response = request.get();

    SearchHit hit = response.getHits().getAt(0);
    if (hit == null) {
      return null;
    } else {
      return toDoc(hit.getSource());
    }
  }
View Full Code Here

        SearchResponse sr = client.prepareSearch(activityLogIndexName).setTypes(activityLogTypeName)
            .setFilter(FilterBuilders.termFilter(ProjectIndexingInfo.DOCFIELD_PROJECT_KEY, projectKey))
            .setQuery(QueryBuilders.matchAllQuery()).addSort(ProjectIndexingInfo.DOCFIELD_START_DATE, SortOrder.DESC)
            .addField("_source").setSize(1).execute().actionGet();
        if (sr.getHits().getTotalHits() > 0) {
          SearchHit hit = sr.getHits().getAt(0);
          lastIndexing = ProjectIndexingInfo.readFromDocument(hit.sourceAsMap());
        } else {
          logger.debug("No last indexing info found in activity log for project {}", projectKey);
        }
      } catch (Exception e) {
        logger.warn("Error during LastProjectIndexingInfo reading from activity log ES index: {} {}", e.getClass()
View Full Code Here

TOP

Related Classes of org.elasticsearch.search.SearchHit

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.