當前位置: 首頁>>代碼示例>>Java>>正文


Java GetResponse.getField方法代碼示例

本文整理匯總了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());
}
 
開發者ID:sherlok,項目名稱:sherlastic,代碼行數:27,代碼來源:SherlokPluginTest.java

示例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;
}
 
開發者ID:jaibeermalik,項目名稱:elasticsearch-tutorial,代碼行數:39,代碼來源:ProductQueryServiceImpl.java

示例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());
}
 
開發者ID:codelibs,項目名稱:elasticsearch-minhash,代碼行數:26,代碼來源:MinHashPluginTest.java

示例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();
}
 
開發者ID:cheng-li,項目名稱:pyramid,代碼行數:19,代碼來源:ESIndex.java

示例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;
}
 
開發者ID:jaibeermalik,項目名稱:searchanalytics-bigdata,代碼行數:56,代碼來源:ProductQueryServiceImpl.java

示例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();

}
 
開發者ID:salyh,項目名稱:elasticsearch-imap,代碼行數:24,代碼來源:ElasticsearchMailDestination.java


注:本文中的org.elasticsearch.action.get.GetResponse.getField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。