Java Code Examples for org.elasticsearch.index.get.GetField#getValues()
The following examples show how to use
org.elasticsearch.index.get.GetField#getValues() .
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 |
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 |
@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 |
@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 |
@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 searchanalytics-bigdata with MIT License | 4 votes |
@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; }