本文整理汇总了Java中org.elasticsearch.search.SearchHitField.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java SearchHitField.getValue方法的具体用法?Java SearchHitField.getValue怎么用?Java SearchHitField.getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.search.SearchHitField
的用法示例。
在下文中一共展示了SearchHitField.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertStoredBinaryFields
import org.elasticsearch.search.SearchHitField; //导入方法依赖的package包/类
/**
* Make sure we can load stored binary fields.
*/
void assertStoredBinaryFields(String indexName, Version version) throws Exception {
SearchRequestBuilder builder = client().prepareSearch(indexName);
builder.setQuery(QueryBuilders.matchAllQuery());
builder.setSize(100);
builder.addStoredField("binary");
SearchHits hits = builder.get().getHits();
assertEquals(100, hits.getHits().length);
for(SearchHit hit : hits) {
SearchHitField field = hit.field("binary");
assertNotNull(field);
Object value = field.getValue();
assertTrue(value instanceof BytesArray);
assertEquals(16, ((BytesArray) value).length());
}
}
示例2: testSimpleFetchAnalyzedText
import org.elasticsearch.search.SearchHitField; //导入方法依赖的package包/类
public void testSimpleFetchAnalyzedText() throws IOException {
client().index(
indexRequest("test").type("type").id("1")
.source(jsonBuilder().startObject().field("test", "I am sam i am").endObject())).actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
ensureGreen();
SearchSourceBuilder searchSource = SearchSourceBuilder.searchSource().ext(
Collections.singletonList(new AnalyzedTextFetchBuilder().field("test")));
SearchResponse response = client().prepareSearch().setSource(searchSource).get();
assertSearchResponse(response);
logger.info(response.toString());
SearchHit hit = response.getHits().getAt(0);
// get the fields from the response
SearchHitField fields = hit.field(AnalyzedTextFetchSubPhase.NAME);
List<String> termVectors = fields.getValue();
assertArrayEquals(termVectors.toArray(new String[termVectors.size()]), new String[]{"i", "am", "sam", "i", "am"});
logger.info("{}", termVectors);
}
示例3: buildDictMatrix
import org.elasticsearch.search.SearchHitField; //导入方法依赖的package包/类
private void buildDictMatrix(SearchHits hits, XContentBuilder builder) throws IOException {
builder.startArray(FieldStrings.MATRIX);
for (SearchHit searchHitFields : hits) {
SearchHitField hitField = searchHitFields.field("matrix");
if (hitField == null) {
continue;
} else {
builder.startObject();
Map<Integer, Integer> value = hitField.getValue();
for (Map.Entry<Integer, Integer> entry : value.entrySet()) {
builder.field(entry.getKey().toString(), entry.getValue());
}
builder.endObject();
}
}
builder.endArray();
}
示例4: fromSearchHit
import org.elasticsearch.search.SearchHitField; //导入方法依赖的package包/类
public static ExtendedDataRowId fromSearchHit(SearchHit hit) {
SearchHitField elementTypeField = hit.getFields().get(Elasticsearch5SearchIndex.ELEMENT_TYPE_FIELD_NAME);
if (elementTypeField == null) {
throw new MemgraphException("Could not find field: " + Elasticsearch5SearchIndex.ELEMENT_TYPE_FIELD_NAME);
}
ElementType elementType = ElasticsearchDocumentType.parse(elementTypeField.getValue().toString()).toElementType();
SearchHitField elementIdField = hit.getFields().get(Elasticsearch5SearchIndex.EXTENDED_DATA_ELEMENT_ID_FIELD_NAME);
if (elementIdField == null) {
throw new MemgraphException("Could not find field: " + Elasticsearch5SearchIndex.EXTENDED_DATA_ELEMENT_ID_FIELD_NAME);
}
String elementId = elementIdField.getValue();
SearchHitField tableNameField = hit.getFields().get(Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_NAME_FIELD_NAME);
if (tableNameField == null) {
throw new MemgraphException("Could not find field: " + Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_NAME_FIELD_NAME);
}
String tableName = tableNameField.getValue();
SearchHitField rowIdField = hit.getFields().get(Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_ROW_ID_FIELD_NAME);
if (rowIdField == null) {
throw new MemgraphException("Could not find field: " + Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_ROW_ID_FIELD_NAME);
}
String rowId = rowIdField.getValue();
return new ExtendedDataRowId(elementType, elementId, tableName, rowId);
}
示例5: nextDoc
import org.elasticsearch.search.SearchHitField; //导入方法依赖的package包/类
void nextDoc(SearchHit hit) {
if (hit.fieldsOrNull() == null) {
hit.fields(new HashMap<>());
}
SearchHitField logs = hit.getFields()
.computeIfAbsent(FIELD_NAME,(k) -> newLogField());
Map<String, List<Map<String, Object>>> entries = logs.getValue();
rebuild();
entries.put(name, currentLog);
}
示例6: fromSearchHit
import org.elasticsearch.search.SearchHitField; //导入方法依赖的package包/类
public static ExtendedDataRowId fromSearchHit(SearchHit hit) {
SearchHitField elementTypeField = hit.getFields().get(Elasticsearch5SearchIndex.ELEMENT_TYPE_FIELD_NAME);
if (elementTypeField == null) {
throw new VertexiumException("Could not find field: " + Elasticsearch5SearchIndex.ELEMENT_TYPE_FIELD_NAME);
}
ElementType elementType = ElasticsearchDocumentType.parse(elementTypeField.getValue().toString()).toElementType();
SearchHitField elementIdField = hit.getFields().get(Elasticsearch5SearchIndex.EXTENDED_DATA_ELEMENT_ID_FIELD_NAME);
if (elementIdField == null) {
throw new VertexiumException("Could not find field: " + Elasticsearch5SearchIndex.EXTENDED_DATA_ELEMENT_ID_FIELD_NAME);
}
String elementId = elementIdField.getValue();
SearchHitField tableNameField = hit.getFields().get(Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_NAME_FIELD_NAME);
if (tableNameField == null) {
throw new VertexiumException("Could not find field: " + Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_NAME_FIELD_NAME);
}
String tableName = tableNameField.getValue();
SearchHitField rowIdField = hit.getFields().get(Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_ROW_ID_FIELD_NAME);
if (rowIdField == null) {
throw new VertexiumException("Could not find field: " + Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_ROW_ID_FIELD_NAME);
}
String rowId = rowIdField.getValue();
return new ExtendedDataRowId(elementType, elementId, tableName, rowId);
}
示例7: getValues
import org.elasticsearch.search.SearchHitField; //导入方法依赖的package包/类
@Override
public String[] getValues(String string) {
String[] values = new String[hit.getFields().size()];
int i=0;
for (SearchHitField field: hit.getFields().values()) {
values[i++] = field.getValue();
}
return values;
}
示例8: buildCOOMatrix
import org.elasticsearch.search.SearchHitField; //导入方法依赖的package包/类
private void buildCOOMatrix(SearchHits hits, XContentBuilder builder) throws IOException {
// NOTE: it would be easier if the sub-matrices could come up already in coo
List<Integer> row = new ArrayList<>();
List<Object> col = new ArrayList<>();
List<Object> data = new ArrayList<>();
int i = 0;
for (SearchHit searchHitFields : hits) {
SearchHitField hitField = searchHitFields.field("matrix");
if (hitField == null) {
continue;
} else {
Map<Integer, Integer> value = hitField.getValue();
col.addAll(value.keySet());
data.addAll(value.values());
Integer[] currentRow = new Integer[value.size()];
Arrays.fill(currentRow, i);
row.addAll(Arrays.asList(currentRow));
}
i++;
}
builder.startObject(FieldStrings.MATRIX);
builder.field(FieldStrings.ROW, row);
builder.field(FieldStrings.COL, col);
builder.field(FieldStrings.DATA, data);
builder.endObject();
}
示例9: sendToLocalCluster
import org.elasticsearch.search.SearchHitField; //导入方法依赖的package包/类
private void sendToLocalCluster(final String scrollId, final SearchHit[] hits) {
// prepare bulk request
final BulkRequestBuilder bulkRequest = client.prepareBulk();
for (final SearchHit hit : hits) {
IndexRequestBuilder builder = client.prepareIndex(toIndex,
toType != null ? toType : hit.getType(), hit.getId())
.setSource(hit.getSource());
Map<String, SearchHitField> fields = hit.getFields();
if (fields != null && fields.containsKey("_parent")) {
SearchHitField parentField = fields.get("_parent");
if (parentField != null) {
String parentId = parentField.getValue();
builder.setParent(parentId);
}
}
bulkRequest.add(builder);
}
// send bulk request, if success response got, searching the next 10 results using scroll_id
// using this listener (inner class) to listen to results
bulkRequest.execute(new ActionListener<BulkResponse>() {
@Override
public void onResponse(final BulkResponse bulkResponse) {
if (bulkResponse.hasFailures()) {
throw new ReindexingException(bulkResponse
.buildFailureMessage());
}
client.prepareSearchScroll(scrollId).setScroll(scroll)
.execute(ReindexingListener.this);
}
@Override
public void onFailure(final Throwable e) {
ReindexingListener.this.onFailure(e);
}
});
}
示例10: getLongValue
import org.elasticsearch.search.SearchHitField; //导入方法依赖的package包/类
protected long getLongValue(final SearchHit hit, final String field) {
final SearchHitField result = hit.field(field);
if (result == null) {
throw new TasteException(field + " is not found.");
}
final Number longValue = result.getValue();
if (longValue == null) {
throw new TasteException("The result of " + field + " is null.");
}
return longValue.longValue();
}
示例11: getFloatValue
import org.elasticsearch.search.SearchHitField; //导入方法依赖的package包/类
protected float getFloatValue(final SearchHit hit, final String field) {
final SearchHitField result = hit.field(field);
if (result == null) {
throw new TasteException(field + " is not found.");
}
final Number floatValue = result.getValue();
if (floatValue == null) {
throw new TasteException("The result of " + field + " is null.");
}
return floatValue.floatValue();
}
示例12: fieldValue
import org.elasticsearch.search.SearchHitField; //导入方法依赖的package包/类
private <T> T fieldValue(String fieldName) {
SearchHitField field = delegate.field(fieldName);
return field == null ? null : field.getValue();
}
示例13: getPreferenceValue
import org.elasticsearch.search.SearchHitField; //导入方法依赖的package包/类
@Override
public Float getPreferenceValue(final long userID, final long itemID) {
if (cache != null) {
final DmValue dmValue = cache.getIfPresent(DmKey.key(
DmKey.PREFERENCE_VALUE, userID, itemID));
if (dmValue != null) {
return dmValue.getValue();
}
}
SearchResponse response;
try {
response = client.prepareSearch(preferenceIndex)
.setTypes(preferenceType)
.setQuery(QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery(itemIdField, itemID))
.must(QueryBuilders.termQuery(userIdField, userID))
.filter(getLastAccessedFilterQuery()))
.addFields(valueField)
.addSort(timestampField, SortOrder.DESC).setSize(1)
.execute().actionGet();
} catch (final ElasticsearchException e) {
throw new TasteException("Failed to get the preference by ("
+ userID + "," + itemID + ")", e);
}
final SearchHits hits = response.getHits();
final long totalHits = hits.getTotalHits();
if (totalHits == 0) {
return null;
} else if (totalHits > 1) {
logger.warn(
"ItemID {} of UserID {} has {} preferences. Use the latest value.",
itemID, userID, totalHits);
}
final SearchHit[] searchHits = hits.getHits();
if (searchHits.length > 0) {
final SearchHitField result = searchHits[0].field(valueField);
if (result != null) {
final Number value = result.getValue();
final float floatValue = value.floatValue();
if (cache != null) {
cache.put(DmKey.create(DmKey.PREFERENCE_VALUE, userID,
itemID), new DmValue(floatValue, 16));
}
return floatValue;
}
}
return null;
}
示例14: getPreferenceTime
import org.elasticsearch.search.SearchHitField; //导入方法依赖的package包/类
@Override
public Long getPreferenceTime(final long userID, final long itemID) {
if (cache != null) {
final DmValue dmValue = cache.getIfPresent(DmKey.key(
DmKey.PREFERENCE_TIME, userID, itemID));
if (dmValue != null) {
return dmValue.getValue();
}
}
SearchResponse response;
try {
response = client
.prepareSearch(preferenceIndex)
.setTypes(preferenceType)
.setQuery(QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery(itemIdField, itemID))
.must(QueryBuilders.termQuery(userIdField, userID))
.filter(getLastAccessedFilterQuery()))
.addFields(timestampField)
.addSort(timestampField, SortOrder.DESC).setSize(1)
.execute().actionGet();
} catch (final ElasticsearchException e) {
throw new TasteException("Failed to get the timestamp by ("
+ userID + "," + itemID + ")", e);
}
final SearchHits hits = response.getHits();
final long totalHits = hits.getTotalHits();
if (totalHits == 0) {
return null;
} else if (totalHits > 1) {
logger.warn(
"ItemID {} of UserID {} has {} preferences. Use the latest value.",
itemID, userID, totalHits);
}
final SearchHit[] searchHits = hits.getHits();
if (searchHits.length > 0) {
final SearchHitField result = searchHits[0].field(timestampField);
if (result != null) {
final Date date = result.getValue();
final long time = date.getTime();
if (cache != null) {
cache.put(
DmKey.create(DmKey.PREFERENCE_TIME, userID, itemID),
new DmValue(time, 16));
}
return time;
}
}
return null;
}
示例15: getTargetIDs
import org.elasticsearch.search.SearchHitField; //导入方法依赖的package包/类
protected long[] getTargetIDs(final String index, final String type,
final String fieldName, final String targetName) {
final Map<String, Object> userSettings = SettingsUtils.get(
rootSettings, targetName);
final String userQuery = SettingsUtils.get(userSettings, "query");
if (StringUtils.isBlank(userQuery)) {
return null;
}
final Number size = SettingsUtils.get(userSettings, "size", 1000);
final Number keepAlive = SettingsUtils.get(userSettings, "keep_alive",
60000); //1min
int count = 0;
long[] targetIDs = null;
SearchResponse response = null;
while (true) {
if (response == null) {
response = client.prepareSearch(index).setTypes(type)
.setScroll(new TimeValue(keepAlive.longValue()))
.setQuery(QueryBuilders.queryStringQuery(userQuery))
.addField(fieldName).setSize(size.intValue()).execute()
.actionGet();
} else {
response = client.prepareSearchScroll(response.getScrollId())
.setScroll(new TimeValue(keepAlive.longValue()))
.execute().actionGet();
}
final SearchHits hits = response.getHits();
if (targetIDs == null) {
targetIDs = new long[(int) hits.getTotalHits()];
if (logger.isDebugEnabled()) {
logger.debug("{} users are found by {}",
hits.getTotalHits(), userQuery);
}
}
if (hits.getHits().length == 0) {
break;
}
for (final SearchHit hit : hits) {
final SearchHitField searchHitField = hit.getFields().get(
fieldName);
final Number value = searchHitField.getValue();
targetIDs[count] = value.longValue();
count++;
}
}
return targetIDs;
}