本文整理匯總了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());
}
示例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;
}
}
示例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;
}
}
示例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));
}