private <T> T fieldValue(String fieldName) { DocumentField field = delegate.field(fieldName); return field == null ? null : field.getValue(); } }
private Optional<SearchHitField> retrieveMessageIdField(SearchHit hit) { if (hit.fields().keySet().contains(JsonMessageConstants.MESSAGE_ID)) { return Optional.ofNullable(hit.field(JsonMessageConstants.MESSAGE_ID)); } else { return Optional.empty(); } }
item.getMetadata().put("type", hit.getType()); if ( hit.fields().containsKey("_timestamp")) { DateTime timestamp = new DateTime(((Long) hit.field("_timestamp").getValue()).longValue()); item.setTimestamp(timestamp);
private <T> T fieldValue(String fieldName) { DocumentField field = delegate.field(fieldName); return field == null ? null : field.getValue(); } }
private <T> T fieldValue(String fieldName) { DocumentField field = delegate.field(fieldName); return field == null ? null : field.getValue(); } }
protected <T> T fieldValue(SearchHit doc, String fieldName) { SearchHitField field = doc.field(fieldName); return field == null ? null : field.<T>value(); }
protected <T> T fieldValue(SearchHit doc, String fieldName) { SearchHitField field = doc.field(fieldName); return field == null ? null : field.<T>value(); }
Object collapseValue = hit.field(collapseBuilder.getField()).getValue(); if (collapseValue != null) { groupQuery.filter(QueryBuilders.matchQuery(collapseBuilder.getField(), collapseValue));
protected Double getDoubleFieldValueOrNull(final SearchHit searchHit, final String fieldName) { final SearchHitField searchHitField = searchHit.field(fieldName); if (searchHitField != null && searchHitField.value() != null) { return Double.valueOf(searchHitField.value().toString()); } return null; }
protected Double getDoubleFieldValueOrNull(SearchHit searchHit, String fieldName) { final SearchHitField searchHitField = searchHit.field(fieldName); if (searchHitField != null && searchHitField.value() != null) { return Double.valueOf(searchHitField.value().toString()); } return null; }
protected String getFieldValueOrNull(final SearchHit searchHit, final String fieldName) { final SearchHitField searchHitField = searchHit.field(fieldName); if (searchHitField != null && searchHitField.value() != null) { return searchHitField.value().toString(); } return null; }
protected String getFieldValueOrNull(SearchHit searchHit, String fieldName) { final SearchHitField searchHitField = searchHit.field(fieldName); if (searchHitField != null && searchHitField.value() != null) { return searchHitField.value().toString(); } return null; }
protected long getLongValue(final SearchHit hit, final String field) { final SearchHitField result = hit.field(field); if (result == null) { throw new TasteException(field + " is not found."); } final Number longValue = result.getValue(); if (longValue == null) { throw new TasteException("The result of " + field + " is null."); } return longValue.longValue(); }
protected float getFloatValue(final SearchHit hit, final String field) { final SearchHitField result = hit.field(field); if (result == null) { throw new TasteException(field + " is not found."); } final Number floatValue = result.getValue(); if (floatValue == null) { throw new TasteException("The result of " + field + " is null."); } return floatValue.floatValue(); }
private Optional<MessageSearchIndex.SearchResult> extractContentFromHit(SearchHit hit) { SearchHitField mailboxId = hit.field(JsonMessageConstants.MAILBOX_ID); SearchHitField uid = hit.field(JsonMessageConstants.UID); Optional<SearchHitField> id = retrieveMessageIdField(hit); if (mailboxId != null && uid != null) { Number uidAsNumber = uid.getValue(); return Optional.of( new MessageSearchIndex.SearchResult( id.map(field -> messageIdFactory.fromString(field.getValue())), mailboxIdFactory.fromString(mailboxId.getValue()), MessageUid.of(uidAsNumber.longValue()))); } else { LOGGER.warn("Can not extract UID, MessageID and/or MailboxId for search result {}", hit.getId()); return Optional.empty(); } }
@Override public List<User> search(QuotaQuery query) { Stream<User> results = new ScrollIterable(client, prepareSearch(query)) .stream() .flatMap(searchResponse -> Arrays.stream(searchResponse.getHits() .getHits())) .map(hit -> hit.field(USER)) .map(field -> (String) field.getValue()) .map(User::fromUsername) .skip(query.getOffset().getValue()); return query.getLimit().getValue() .map(results::limit) .orElse(results) .collect(Guavate.toImmutableList()); }
/** * It basically searches and returns a set of tweet ids for a given keyword. * * @param keyword * @return */ public Set<String> search(String keyword) { SearchResponse response; try { response = client.prepareSearch() .setIndices("hackaton") .setTypes("tweets") .addFields("id", "text") .setQuery(QueryBuilders.fieldQuery("text", keyword)).execute().actionGet(); } catch (Throwable e) { return new HashSet<String>(); } Set<String> result = new HashSet<String>(); for (SearchHit hit : response.getHits()) { Long id = hit.field("id").<Long>getValue(); result.add(String.valueOf(id)); } return result; }
/** * Creates a NamedList for the for document highlighting response * * @param request the ES RestRequest * @param response the ES SearchResponse * @return a NamedList if highlighting was requested, null if not */ private NamedList<Object> createHighlightResponse(RestRequest request, SearchResponse response) { NamedList<Object> highlightResponse = null; // if highlighting was requested create the NamedList for the highlights if (request.paramAsBoolean("hl", false)) { highlightResponse = new SimpleOrderedMap<Object>(); SearchHits hits = response.getHits(); // for each hit, get each highlight field and put the list // of highlight fragments in a NamedList specific to the hit for (SearchHit hit : hits.getHits()) { NamedList<Object> docHighlights = new SimpleOrderedMap<Object>(); Map<String, HighlightField> highlightFields = hit.getHighlightFields(); for (String fieldName : highlightFields.keySet()) { HighlightField highlightField = highlightFields.get(fieldName); docHighlights.add(fieldName, highlightField.getFragments()); } // highlighting by placing the doc highlights in the response // based on the document id highlightResponse.add(hit.field("id").getValue().toString(), docHighlights); } } // return the highlight response return highlightResponse; }
final SearchHitField result = searchHits[0].field(valueField); if (result != null) { final Number value = result.getValue();