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


Java SearchHitField.getValues方法代碼示例

本文整理匯總了Java中org.elasticsearch.search.SearchHitField.getValues方法的典型用法代碼示例。如果您正苦於以下問題:Java SearchHitField.getValues方法的具體用法?Java SearchHitField.getValues怎麽用?Java SearchHitField.getValues使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.search.SearchHitField的用法示例。


在下文中一共展示了SearchHitField.getValues方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testScriptFieldsForNullReturn

import org.elasticsearch.search.SearchHitField; //導入方法依賴的package包/類
public void testScriptFieldsForNullReturn() throws Exception {
    client().prepareIndex("test", "type1", "1")
            .setSource("foo", "bar")
            .setRefreshPolicy("true").get();

    SearchResponse response = client().prepareSearch()
            .setQuery(matchAllQuery())
            .addScriptField("test_script_1",
                new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "return null", Collections.emptyMap()))
            .get();

    assertNoFailures(response);

    SearchHitField fieldObj = response.getHits().getAt(0).field("test_script_1");
    assertThat(fieldObj, notNullValue());
    List<?> fieldValues = fieldObj.getValues();
    assertThat(fieldValues, hasSize(1));
    assertThat(fieldValues.get(0), nullValue());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:SearchFieldsIT.java

示例2: buildJSONFromFields

import org.elasticsearch.search.SearchHitField; //導入方法依賴的package包/類
private String buildJSONFromFields(Collection<SearchHitField> values) {
	JsonFactory nodeFactory = new JsonFactory();
	try {
		ByteArrayOutputStream stream = new ByteArrayOutputStream();
		JsonGenerator generator = nodeFactory.createGenerator(stream, JsonEncoding.UTF8);
		generator.writeStartObject();
		for (SearchHitField value : values) {
			if (value.getValues().size() > 1) {
				generator.writeArrayFieldStart(value.getName());
				for (Object val : value.getValues()) {
					generator.writeObject(val);
				}
				generator.writeEndArray();
			} else {
				generator.writeObjectField(value.getName(), value.getValue());
			}
		}
		generator.writeEndObject();
		generator.flush();
		return new String(stream.toByteArray(), Charset.forName("UTF-8"));
	} catch (IOException e) {
		return null;
	}
}
 
開發者ID:uckefu,項目名稱:uckefu,代碼行數:25,代碼來源:UKResultMapper.java

示例3: buildJSONFromFields

import org.elasticsearch.search.SearchHitField; //導入方法依賴的package包/類
private String buildJSONFromFields(Collection<SearchHitField> values) {
JsonFactory nodeFactory = new JsonFactory();
try {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    JsonGenerator generator = nodeFactory.createGenerator(stream, JsonEncoding.UTF8);
    generator.writeStartObject();
    for (SearchHitField value : values) {
	if (value.getValues().size() > 1) {
	    generator.writeArrayFieldStart(value.getName());
	    for (Object val : value.getValues()) {
		generator.writeObject(val);
	    }
	    generator.writeEndArray();
	} else {
	    generator.writeObjectField(value.getName(), value.getValue());
	}
    }
    generator.writeEndObject();
    generator.flush();
    return new String(stream.toByteArray(), Charset.forName("UTF-8"));
} catch (IOException e) {
    LOG.error("IOException in buildJSONFromFields ", e);
    return null;
}
   }
 
開發者ID:dlcs,項目名稱:the-mathmos-server,代碼行數:26,代碼來源:TextSearchAnnotationMapper.java

示例4: putField

import org.elasticsearch.search.SearchHitField; //導入方法依賴的package包/類
void putField(ObjectNode json, SearchHitField field) {
    String fieldName = field.getName();
    String[] nameParts = fieldName.split("\\.");
    String property = nameParts[nameParts.length - 1];
    ObjectNode obj = json;
    for (int i = 0; i < nameParts.length - 1; ++i) {
        String part = nameParts[i];
        obj = obj.with(part);
    }
    List<Object> values = field.getValues();
    Object value = values.size() > 1 ? values : values.get(0);
    obj.put(property, nodeFactory.pojoNode(value));
}
 
開發者ID:scaleset,項目名稱:scaleset-search,代碼行數:14,代碼來源:AbstractSearchMapping.java


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