本文整理汇总了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));
}