org.elasticsearch.index.get.GetField Java Examples

The following examples show how to use org.elasticsearch.index.get.GetField. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShardTermVectorsService.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private Fields generateTermVectors(Collection<GetField> getFields, boolean withOffsets, @Nullable Map<String, String> perFieldAnalyzer, Set<String> fields)
        throws IOException {
    /* store document in memory index */
    MemoryIndex index = new MemoryIndex(withOffsets);
    for (GetField getField : getFields) {
        String field = getField.getName();
        if (fields.contains(field) == false) {
            // some fields are returned even when not asked for, eg. _timestamp
            continue;
        }
        Analyzer analyzer = getAnalyzerAtField(field, perFieldAnalyzer);
        for (Object text : getField.getValues()) {
            index.addField(field, text.toString(), analyzer);
        }
    }
    /* and read vectors from it */
    return MultiFields.getFields(index.createSearcher().getIndexReader());
}
 
Example #2
Source File: ProductQueryServiceImpl.java    From elasticsearch-tutorial with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected List<String> getListFieldValueOrNull(GetField field)
{
    if(field !=null)
    {
        final List<String> list = new ArrayList<String>();
        for (final Object object : field.getValues())
        {
            if(object instanceof List)
            {
                for (final String valueString : (List<String>)object)
                {
                    list.add(String.valueOf(valueString));
                }
            }
            else
            {
                list.add(String.valueOf(object));
            }
        }
        return list;
    }
    return null;
}
 
Example #3
Source File: ProductQueryServiceImpl.java    From searchanalytics-bigdata with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected List<String> getListFieldValueOrNull(final GetField field) {
	if (field != null) {
		final List<String> list = new ArrayList<String>();
		for (final Object object : field.getValues()) {
			if (object instanceof List) {
				for (final String valueString : (List<String>) object) {
					list.add(String.valueOf(valueString));
				}
			} else {
				list.add(String.valueOf(object));
			}
		}
		return list;
	}
	return null;
}
 
Example #4
Source File: ProductQueryServiceImpl.java    From elasticsearch-tutorial with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Product getProduct(ElasticSearchIndexConfig config, Long productId)
{
    GetResponse getResponse = searchClientService.getClient().prepareGet(config.getIndexAliasName(), config.getDocumentType(), String.valueOf(productId))
                                                             .setFields(SearchDocumentFieldName.productDocumentFields)
                                                             .get();
    if(getResponse.isExists())
    {
        Product product = new Product();
        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()));
        GetField catField = getResponse.getField(SearchDocumentFieldName.CATEGORIES_ARRAY.getFieldName());
        if(catField !=null)
        {
            for (Object ListOfMapValues : catField.getValues())
            {
                for (final java.util.Map.Entry<String, String> entry : ((Map<String, String>)ListOfMapValues).entrySet())
                {
                    //Only main facet values should be set.key ending with a number.
                    if(entry.getKey().matches("^.*.facet$"))
                    {
                        product.addCategory(new Category(entry.getValue(), null, entry.getKey().split("\\.facet")[0]));
                    }
                }
            }
        }
        
        return product;
    }
    return null;
}
 
Example #5
Source File: ProductQueryServiceImpl.java    From elasticsearch-tutorial with MIT License 5 votes vote down vote up
protected String getStringFieldValue(GetField field)
{
    if(field !=null)
    {
        return String.valueOf(field.getValue());
    }
    return null;
}
 
Example #6
Source File: ProductQueryServiceImpl.java    From elasticsearch-tutorial with MIT License 5 votes vote down vote up
protected Date getDateFieldValueOrNull(GetField field)
{
    if(field !=null)
    {
        final String dateString = String.valueOf(field.getValue());
        if(dateString !=null && !dateString.isEmpty())
        {
            return SearchDateUtils.getFormattedDate(dateString);
        }
    }
    return null;
}
 
Example #7
Source File: ProductQueryServiceImpl.java    From elasticsearch-tutorial with MIT License 5 votes vote down vote up
protected boolean getBooleanFieldValueOrFalse(GetField field)
{
    if(field !=null)
    {
        return Boolean.valueOf(String.valueOf(field.getValue()));
    }
    return false;
}
 
Example #8
Source File: ProductQueryServiceImpl.java    From searchanalytics-bigdata with MIT License 5 votes vote down vote up
protected Date getDateFieldValueOrNull(final GetField field) {
	if (field != null) {
		final String dateString = String.valueOf(field.getValue());
		if (dateString != null && !dateString.isEmpty()) {
			return SearchDateUtils.getFormattedDate(dateString);
		}
	}
	return null;
}
 
Example #9
Source File: GetResponse.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public Map<String, GetField> getFields() {
    return getResult.getFields();
}
 
Example #10
Source File: GetResponse.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public GetField getField(String name) {
    return getResult.field(name);
}
 
Example #11
Source File: GetResponse.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public Iterator<GetField> iterator() {
    return getResult.iterator();
}
 
Example #12
Source File: GetIndexedScriptResponse.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public Iterator<GetField> iterator() {
    return getResponse.iterator();
}
 
Example #13
Source File: ProductQueryServiceImpl.java    From searchanalytics-bigdata with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Product getProduct(final ElasticSearchIndexConfig config,
		final Long productId) {
	final GetResponse getResponse = searchClientService
			.getClient()
			.prepareGet(config.getIndexAliasName(),
					config.getDocumentType(), String.valueOf(productId))
			.setFields(SearchDocumentFieldName.productDocumentFields).get();
	if (getResponse.isExists()) {
		final Product product = new Product();
		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) {
			for (final Object ListOfMapValues : catField.getValues()) {
				for (final java.util.Map.Entry<String, String> entry : ((Map<String, String>) ListOfMapValues)
						.entrySet()) {
					// Only main facet values should be set.key ending with
					// a number.
					if (entry.getKey().matches("^.*.facet$")) {
						product.addCategory(new Category(entry.getValue(),
								null, entry.getKey().split("\\.facet")[0]));
					}
				}
			}
		}
		return product;
	}
	return null;
}
 
Example #14
Source File: ProductQueryServiceImpl.java    From searchanalytics-bigdata with MIT License 4 votes vote down vote up
protected String getStringFieldValue(final GetField field) {
	if (field != null) {
		return String.valueOf(field.getValue());
	}
	return null;
}
 
Example #15
Source File: ProductQueryServiceImpl.java    From searchanalytics-bigdata with MIT License 4 votes vote down vote up
protected boolean getBooleanFieldValueOrFalse(final GetField field) {
	if (field != null) {
		return Boolean.valueOf(String.valueOf(field.getValue()));
	}
	return false;
}
 
Example #16
Source File: ElasticsearchMailDestination.java    From elasticsearch-imap with Apache License 2.0 4 votes vote down vote up
@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();

}