本文整理汇总了Java中org.elasticsearch.search.SearchHit.getFields方法的典型用法代码示例。如果您正苦于以下问题:Java SearchHit.getFields方法的具体用法?Java SearchHit.getFields怎么用?Java SearchHit.getFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.search.SearchHit
的用法示例。
在下文中一共展示了SearchHit.getFields方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createKeyToResultsAndFillOptimizationStructure
import org.elasticsearch.search.SearchHit; //导入方法依赖的package包/类
private void createKeyToResultsAndFillOptimizationStructure(Map<String,Map<String, List<Object>>> optimizationTermsFilterStructure, TableInJoinRequestBuilder firstTableRequest) {
List<SearchHit> firstTableHits = fetchAllHits(firstTableRequest);
int resultIds = 1;
for (SearchHit hit : firstTableHits) {
HashMap<String, List<Map.Entry<Field, Field>>> comparisons = this.hashJoinComparisonStructure.getComparisons();
for (Map.Entry<String, List<Map.Entry<Field, Field>>> comparison : comparisons.entrySet()) {
String comparisonID = comparison.getKey();
List<Map.Entry<Field, Field>> t1ToT2FieldsComparison = comparison.getValue();
String key = getComparisonKey(t1ToT2FieldsComparison, hit, true, optimizationTermsFilterStructure.get(comparisonID));
//int docid , id
InternalSearchHit searchHit = new InternalSearchHit(resultIds, hit.id(), new Text(hit.getType()), hit.getFields());
searchHit.sourceRef(hit.getSourceRef());
onlyReturnedFields(searchHit.sourceAsMap(), firstTableRequest.getReturnedFields(),firstTableRequest.getOriginalSelect().isSelectAll());
resultIds++;
this.hashJoinComparisonStructure.insertIntoComparisonHash(comparisonID, key, searchHit);
}
}
}
示例2: SearchResult
import org.elasticsearch.search.SearchHit; //导入方法依赖的package包/类
public SearchResult(SearchResponse resp) {
SearchHits hits = resp.getHits();
this.total = hits.getTotalHits();
results = new ArrayList<>(hits.getHits().length);
for (SearchHit searchHit : hits.getHits()) {
if (searchHit.getSource() != null) {
results.add(searchHit.getSource());
} else if (searchHit.getFields() != null) {
Map<String, SearchHitField> fields = searchHit.getFields();
results.add(toFieldsMap(fields));
}
}
}
示例3: testScriptFields
import org.elasticsearch.search.SearchHit; //导入方法依赖的package包/类
public void testScriptFields() throws Exception {
assertAcked(prepareCreate("index").addMapping("type",
"s", "type=keyword",
"l", "type=long",
"d", "type=double",
"ms", "type=keyword",
"ml", "type=long",
"md", "type=double").get());
final int numDocs = randomIntBetween(3, 8);
List<IndexRequestBuilder> reqs = new ArrayList<>();
for (int i = 0; i < numDocs; ++i) {
reqs.add(client().prepareIndex("index", "type", Integer.toString(i)).setSource(
"s", Integer.toString(i),
"ms", new String[] {Integer.toString(i), Integer.toString(i+1)},
"l", i,
"ml", new long[] {i, i+1},
"d", i,
"md", new double[] {i, i+1}));
}
indexRandom(true, reqs);
ensureSearchable();
SearchRequestBuilder req = client().prepareSearch("index");
for (String field : Arrays.asList("s", "ms", "l", "ml", "d", "md")) {
req.addScriptField(field,
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['" + field + "'].values", Collections.emptyMap()));
}
SearchResponse resp = req.get();
assertSearchResponse(resp);
for (SearchHit hit : resp.getHits().getHits()) {
final int id = Integer.parseInt(hit.getId());
Map<String, SearchHitField> fields = hit.getFields();
assertThat(fields.get("s").getValues(), equalTo(Collections.<Object> singletonList(Integer.toString(id))));
assertThat(fields.get("l").getValues(), equalTo(Collections.<Object> singletonList((long) id)));
assertThat(fields.get("d").getValues(), equalTo(Collections.<Object> singletonList((double) id)));
assertThat(fields.get("ms").getValues(), equalTo(Arrays.<Object> asList(Integer.toString(id), Integer.toString(id + 1))));
assertThat(fields.get("ml").getValues(), equalTo(Arrays.<Object> asList((long) id, id + 1L)));
assertThat(fields.get("md").getValues(), equalTo(Arrays.<Object> asList((double) id, id + 1d)));
}
}
示例4: createUnmachedResult
import org.elasticsearch.search.SearchHit; //导入方法依赖的package包/类
protected InternalSearchHit createUnmachedResult( List<Field> secondTableReturnedFields, int docId, String t1Alias, String t2Alias, SearchHit hit) {
String unmatchedId = hit.id() + "|0";
Text unamatchedType = new Text(hit.getType() + "|null");
InternalSearchHit searchHit = new InternalSearchHit(docId, unmatchedId, unamatchedType, hit.getFields());
searchHit.sourceRef(hit.getSourceRef());
searchHit.sourceAsMap().clear();
searchHit.sourceAsMap().putAll(hit.sourceAsMap());
Map<String,Object> emptySecondTableHitSource = createNullsSource(secondTableReturnedFields);
mergeSourceAndAddAliases(emptySecondTableHitSource, searchHit,t1Alias,t2Alias);
return searchHit;
}
示例5: getMergedHit
import org.elasticsearch.search.SearchHit; //导入方法依赖的package包/类
private InternalSearchHit getMergedHit(int currentCombinedResults, String t1Alias, String t2Alias, SearchHit hitFromFirstTable, SearchHit matchedHit) {
onlyReturnedFields(matchedHit.sourceAsMap(), nestedLoopsRequest.getSecondTable().getReturnedFields(),nestedLoopsRequest.getSecondTable().getOriginalSelect().isSelectAll());
InternalSearchHit searchHit = new InternalSearchHit(currentCombinedResults, hitFromFirstTable.id() + "|" + matchedHit.getId(), new Text(hitFromFirstTable.getType() + "|" + matchedHit.getType()), hitFromFirstTable.getFields());
searchHit.sourceRef(hitFromFirstTable.getSourceRef());
searchHit.sourceAsMap().clear();
searchHit.sourceAsMap().putAll(hitFromFirstTable.sourceAsMap());
mergeSourceAndAddAliases(matchedHit.getSource(), searchHit, t1Alias, t2Alias);
return searchHit;
}
示例6: createHeadersAndFillDocsMap
import org.elasticsearch.search.SearchHit; //导入方法依赖的package包/类
private List<String> createHeadersAndFillDocsMap(boolean flat, SearchHit[] hits, List<Map<String, Object>> docsAsMap) {
Set<String> csvHeaders = new HashSet<>();
for(SearchHit hit : hits){
Map<String, Object> doc = hit.sourceAsMap();
Map<String, SearchHitField> fields = hit.getFields();
for(SearchHitField searchHitField : fields.values()){
doc.put(searchHitField.getName(),searchHitField.value());
}
mergeHeaders(csvHeaders, doc, flat);
if(this.indcludeId){
doc.put("_id", hit.id());
}
if(this.includeScore){
doc.put("_score", hit.score());
}
if(this.includeType){
doc.put("_type",hit.type());
}
docsAsMap.add(doc);
}
ArrayList<String> headersList = new ArrayList<>(csvHeaders);
if (this.indcludeId){
headersList.add("_id");
}
if (this.includeScore){
headersList.add("_score");
}
if (this.includeType){
headersList.add("_type");
}
return headersList;
}
示例7: createHeadersAndFillDocsMap
import org.elasticsearch.search.SearchHit; //导入方法依赖的package包/类
private List<String> createHeadersAndFillDocsMap(boolean flat, SearchHit[] hits, List<Map<String, Object>> docsAsMap) {
Set<String> csvHeaders = new HashSet<>();
for (SearchHit hit : hits) {
Map<String, Object> doc = hit.sourceAsMap();
Map<String, SearchHitField> fields = hit.getFields();
for (SearchHitField searchHitField : fields.values()) {
doc.put(searchHitField.getName(), searchHitField.value());
}
mergeHeaders(csvHeaders, doc, flat);
if (this.includeScore) {
doc.put("_score", hit.score());
}
if (this.includeType) {
doc.put("_type", hit.type());
}
if (this.includeId) {
doc.put("_id", hit.id());
}
docsAsMap.add(doc);
}
ArrayList<String> headersList = new ArrayList<>(csvHeaders);
if (this.includeScore) {
headersList.add("_score");
}
if (this.includeType) {
headersList.add("_type");
}
if (this.includeId) {
headersList.add("_id");
}
return headersList;
}