private Optional<String> getMetadata(String id) { GetRequestBuilder request = esClient.prepareGet(MetadataIndexDefinition.INDEX_TYPE_METADATA, id) .setStoredFields(MetadataIndexDefinition.FIELD_VALUE); GetResponse response = request.get(); if (response.isExists()) { GetField field = response.getField(MetadataIndexDefinition.FIELD_VALUE); String value = String.valueOf(field.getValue()); return Optional.of(value); } return Optional.empty(); }
public ElasticsearchSample get(Object key, String... fields) { GetResponse getResponse = client.prepareGet(index, type, String.valueOf(key)).setFields(fields).execute() .actionGet(); Map<String, Object> map = new TreeMap<String, Object>(); map.put(ID, getResponse.getId()); for (String k : getResponse.getFields().keySet()) { map.put(k, getResponse.getField(k).getValue()); } return new ElasticsearchSample(this, map); }
public static Long getFieldValueLong(GetResponse getResponse, String fieldName) { GetField field = getResponse.getField(fieldName); if (field == null) { return null; } Object value = field.getValue(); if (value instanceof Integer) { return ((Integer) value).longValue(); } return (Long) value; } }
public static String getFieldValueString(GetResponse getResponse, String fieldName) { GetField field = getResponse.getField(fieldName); if (field == null) { return null; } return (String) field.getValue(); }
public static Long getFieldValueLong(GetResponse getResponse, String fieldName) { GetField field = getResponse.getField(fieldName); if (field == null) { return null; } Object value = field.getValue(); if (value instanceof Integer) { return ((Integer) value).longValue(); } return (Long) value; } }
public static Long getFieldValueLong(GetResponse getResponse, String fieldName) { GetField field = getResponse.getField(fieldName); if (field == null) { return null; } Object value = field.getValue(); if (value instanceof Integer) { return ((Integer) value).longValue(); } return (Long) value; } }
public static Long getFieldValueLong(GetResponse getResponse, String fieldName) { GetField field = getResponse.getField(fieldName); if (field == null) { return null; } Object value = field.getValue(); if (value instanceof Integer) { return ((Integer) value).longValue(); } return (Long) value; } }
public static String getFieldValueString(GetResponse getResponse, String fieldName) { GetField field = getResponse.getField(fieldName); if (field == null) { return null; } return (String) field.getValue(); }
public static String getFieldValueString(GetResponse getResponse, String fieldName) { GetField field = getResponse.getField(fieldName); if (field == null) { return null; } return (String) field.getValue(); }
public static Long getFieldValueLong(GetResponse getResponse, String fieldName) { GetField field = getResponse.getField(fieldName); if (field == null) { return null; } Object value = field.getValue(); if (value instanceof Integer) { return ((Integer) value).longValue(); } return (Long) value; } }
public static String getFieldValueString(GetResponse getResponse, String fieldName) { GetField field = getResponse.getField(fieldName); if (field == null) { return null; } return (String) field.getValue(); }
public static String getFieldValueString(GetResponse getResponse, String fieldName) { GetField field = getResponse.getField(fieldName); if (field == null) { return null; } return (String) field.getValue(); }
public List<Object> getListField(String id, String field){ GetResponse response = client.prepareGet(this.indexName, this.documentType, id). setStoredFields(field) .execute() .actionGet(); if (response==null){ if (logger.isWarnEnabled()){ logger.warn("no response from document "+id+" when fetching field "+field+"!"); } return new ArrayList<>(); }else if (response.getField(field)==null){ if (logger.isWarnEnabled()) { logger.warn("document " + id + " has no field " + field + "!"); } return new ArrayList<>(); } return response.getField(field).getValues(); }
private Optional<String> getMetadata(String id) { GetRequestBuilder request = esClient.prepareGet(MetadataIndexDefinition.INDEX_TYPE_METADATA, id) .setStoredFields(MetadataIndexDefinition.FIELD_VALUE); GetResponse response = request.get(); if (response.isExists()) { GetField field = response.getField(MetadataIndexDefinition.FIELD_VALUE); String value = String.valueOf(field.getValue()); return Optional.of(value); } return Optional.empty(); }
product.setTitle(getResponse.getField(SearchDocumentFieldName.TITLE.getFieldName()).getValue().toString()); product.setDescription(getResponse.getField(SearchDocumentFieldName.DESCRIPTION.getFieldName()).getValue().toString()); product.setSoldOut(Boolean.valueOf(getResponse.getField(SearchDocumentFieldName.SOLD_OUT.getFieldName()).getValue().toString())); product.setAvailableOn(SearchDateUtils.getFormattedDate(getResponse.getField(SearchDocumentFieldName.AVAILABLE_DATE.getFieldName()).getValue().toString())); product.setKeywords(getListFieldValueOrNull(getResponse.getField(SearchDocumentFieldName.KEYWORDS.getFieldName()))); product.setPrice(BigDecimal.valueOf(Double.valueOf(getResponse.getField(SearchDocumentFieldName.PRICE.getFieldName()).getValue().toString()))); product.setBoostFactor(Float.valueOf(getResponse.getField(SearchDocumentFieldName.BOOSTFACTOR.getFieldName()).getValue().toString())); GetField catField = getResponse.getField(SearchDocumentFieldName.CATEGORIES_ARRAY.getFieldName()); if(catField !=null)
product.setId(Long.valueOf(getResponse.getId())); product.setTitle(getResponse .getField(SearchDocumentFieldName.TITLE.getFieldName()) .getValue().toString()); product.setDescription(getResponse .getField( SearchDocumentFieldName.DESCRIPTION.getFieldName()) .getValue().toString()); product.setSoldOut(Boolean.valueOf(getResponse .getField(SearchDocumentFieldName.SOLD_OUT.getFieldName()) .getValue().toString())); product.setAvailableOn(SearchDateUtils.getFormattedDate(getResponse .getField( SearchDocumentFieldName.AVAILABLE_DATE .getFieldName()).getValue().toString())); product.setKeywords(getListFieldValueOrNull(getResponse .getField(SearchDocumentFieldName.KEYWORDS.getFieldName()))); product.setPrice(BigDecimal.valueOf(Double.valueOf(getResponse .getField(SearchDocumentFieldName.PRICE.getFieldName()) .getValue().toString()))); product.setBoostFactor(Float.valueOf(getResponse .getField( SearchDocumentFieldName.BOOSTFACTOR.getFieldName()) .getValue().toString())); final GetField catField = getResponse .getField(SearchDocumentFieldName.CATEGORIES_ARRAY .getFieldName()); if (catField != null) {
@Override public int getFlaghashcode(final String id) throws IOException, MessagingException { createIndexIfNotExists(); client.admin().indices().refresh(new RefreshRequest()).actionGet(); final GetResponse getResponse = client.prepareGet().setIndex(index).setType(type).setId(id) .setFields(new String[] { "flaghashcode" }).execute().actionGet(); if (getResponse == null || !getResponse.isExists()) { return -1; } final GetField flaghashcodeField = getResponse.getField("flaghashcode"); if (flaghashcodeField == null || flaghashcodeField.getValue() == null || !(flaghashcodeField.getValue() instanceof Number)) { throw new IOException("No flaghashcode field for id " + id+ " ("+(flaghashcodeField==null?"null":"Val: "+flaghashcodeField.getValue())+")"); } return ((Number) flaghashcodeField.getValue()).intValue(); }
@Override public List<StreamsDatum> process(StreamsDatum entry) { List<StreamsDatum> result = new ArrayList<>(); if (entry == null || entry.getMetadata() == null) { return result; } Map<String, Object> metadata = entry.getMetadata(); String index = ElasticsearchMetadataUtil.getIndex(metadata, config); String type = ElasticsearchMetadataUtil.getType(metadata, config); String id = ElasticsearchMetadataUtil.getId(entry); GetRequestBuilder getRequestBuilder = elasticsearchClientManager.client().prepareGet(index, type, id); getRequestBuilder.setFields("*", "_timestamp"); getRequestBuilder.setFetchSource(true); GetResponse getResponse = getRequestBuilder.get(); if ( getResponse == null || !getResponse.isExists() || getResponse.isSourceEmpty() ) { return result; } entry.setDocument(getResponse.getSource()); if ( getResponse.getField("_timestamp") != null) { DateTime timestamp = new DateTime(((Long) getResponse.getField("_timestamp").getValue()).longValue()); entry.setTimestamp(timestamp); } result.add(entry); return result; }
@Override public UserIdentity loadUser(String user) { Log.debug("attempting to load user [{}]", user); try { GetResponse response = client.prepareGet(authIndex, authType, user) .setFields(passwordField, rolesField) .execute().actionGet(); if (response.isExists()) { Log.debug("user [{}] exists; looking for credentials...", user); Credential credential = null; GetField passwordGetField = response.getField(passwordField); if (passwordGetField != null) { Log.debug("user [{}] using password auth", user); credential = Credential.getCredential((String) passwordGetField.getValue()); } String[] roles = getStringValues(response.getField(rolesField)); return putUser(user, credential, roles); } } catch (IndexMissingException e) { Log.warn("no auth index [{}]", authIndex); } catch (Exception e) { Log.warn("error finding user [" + user + "] in [" + authIndex + "]", e); } return null; }