本文整理汇总了Java中org.elasticsearch.action.get.GetResponse.getField方法的典型用法代码示例。如果您正苦于以下问题:Java GetResponse.getField方法的具体用法?Java GetResponse.getField怎么用?Java GetResponse.getField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.get.GetResponse
的用法示例。
在下文中一共展示了GetResponse.getField方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_get
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
private void test_get(final Client client, final String index,
final String type, final String id, final byte[] hash1,
final byte[] hash2, final byte[] hash3) {
final GetResponse response = client
.prepareGet(index, type, id)
.setFields("_source", "minhash_value1", "minhash_value2",
"minhash_value3").execute().actionGet();
assertTrue(response.isExists());
final Map<String, Object> source = response.getSourceAsMap();
assertEquals("test " + Integer.parseInt(id) % 100, source.get("msg"));
final GetField field1 = response.getField("minhash_value1");
final BytesArray value1 = (BytesArray) field1.getValue();
assertEquals(hash1.length, value1.length());
Assert.assertArrayEquals(hash1, value1.array());
final GetField field2 = response.getField("minhash_value2");
final BytesArray value2 = (BytesArray) field2.getValue();
assertEquals(hash2.length, value2.length());
Assert.assertArrayEquals(hash2, value2.array());
final GetField field3 = response.getField("minhash_value3");
final BytesArray value3 = (BytesArray) field3.getValue();
assertEquals(hash3.length, value3.length());
Assert.assertArrayEquals(hash3, value3.array());
}
示例2: getProduct
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@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;
}
示例3: test_get
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
private void test_get(final Client client, final String index,
final String type, final String id, final byte[] hash1,
final byte[] hash2, final byte[] hash3) {
final GetResponse response = client.prepareGet(index, type, id)
.setStoredFields(new String[] { "_source", "minhash_value1", "minhash_value2", "minhash_value3" }).execute()
.actionGet();
assertTrue(response.isExists());
final Map<String, Object> source = response.getSourceAsMap();
assertEquals("test " + Integer.parseInt(id) % 100, source.get("msg"));
final DocumentField field1 = response.getField("minhash_value1");
final BytesArray value1 = (BytesArray) field1.getValue();
assertEquals(hash1.length, value1.length());
Assert.assertArrayEquals(hash1, value1.array());
final DocumentField field2 = response.getField("minhash_value2");
final BytesArray value2 = (BytesArray) field2.getValue();
assertEquals(hash2.length, value2.length());
Assert.assertArrayEquals(hash2, value2.array());
final DocumentField field3 = response.getField("minhash_value3");
final BytesArray value3 = (BytesArray) field3.getValue();
assertEquals(hash3.length, value3.length());
Assert.assertArrayEquals(hash3, value3.array());
}
示例4: getListField
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
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();
}
示例5: transform
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@Override
public String[] transform(InputRow row) {
try {
final ElasticSearchDataContext dataContext = (ElasticSearchDataContext) _connection.getDataContext();
final Client client = dataContext.getElasticSearchClient();
final String[] result = new String[fields.length];
final String id = ConvertToStringTransformer.transformValue(row.getValue(documentId));
logger.info("Id is {}", id);
if (StringUtils.isNullOrEmpty(id)) {
return result;
}
final GetRequest request = new GetRequestBuilder(client).setId(id).setType(documentType).setFields(fields)
.setIndex(elasticsearchDatastore.getIndexName()).setOperationThreaded(false).request();
final ActionFuture<GetResponse> getFuture = client.get(request);
final GetResponse response = getFuture.actionGet();
logger.info("Response is {}", response);
if (!response.isExists()) {
return result;
}
for (int i = 0; i < fields.length; i++) {
final String field = fields[i];
final GetField valueGetter = response.getField(field);
if (valueGetter == null) {
logger.info("Document with id '{}' did not have the field '{}'", id, field);
} else {
final Object value = valueGetter.getValue();
result[i] = ConvertToStringTransformer.transformValue(value);
}
}
return result;
} catch (Exception e) {
logger.error("Exception while running the ElasticSearchDocumentIdLookupTransformer", e);
throw e;
}
}
开发者ID:datacleaner,项目名称:extension_elasticsearch,代码行数:41,代码来源:ElasticSearchDocumentIdLookupTransformer.java
示例6: getProduct
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@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;
}
示例7: getFlaghashcode
import org.elasticsearch.action.get.GetResponse; //导入方法依赖的package包/类
@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();
}