本文整理汇总了Java中org.elasticsearch.search.internal.InternalSearchHit类的典型用法代码示例。如果您正苦于以下问题:Java InternalSearchHit类的具体用法?Java InternalSearchHit怎么用?Java InternalSearchHit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InternalSearchHit类属于org.elasticsearch.search.internal包,在下文中一共展示了InternalSearchHit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的package包/类
public void initialize(Engine.Searcher docSearcher, ParsedDocument parsedDocument) {
this.docSearcher = docSearcher;
IndexReader indexReader = docSearcher.reader();
LeafReaderContext atomicReaderContext = indexReader.leaves().get(0);
LeafSearchLookup leafLookup = lookup().getLeafSearchLookup(atomicReaderContext);
leafLookup.setDocument(0);
leafLookup.source().setSource(parsedDocument.source());
Map<String, SearchHitField> fields = new HashMap<>();
for (IndexableField field : parsedDocument.rootDoc().getFields()) {
fields.put(field.name(), new InternalSearchHitField(field.name(), Collections.emptyList()));
}
hitContext().reset(
new InternalSearchHit(0, "unknown", new Text(parsedDocument.type()), fields),
atomicReaderContext, 0, docSearcher.searcher()
);
}
示例2: reindex
import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的package包/类
private void reindex(QueryFetchSearchResult hits, String index, String type) {
logger.debug("Reindex: [index:{}, type:{}]", index, type);
if (state == IndexShardState.STARTED) {
for (InternalSearchHit hit : hits.fetchResult().hits().internalHits()) {
// no difference between PRIMARY and REPLICA
SourceToParse source = SourceToParse.source(SourceToParse.Origin.REPLICA, hit.sourceRef())
.index(index).type(type).id(hit.id());
if (hit.field(ParentFieldMapper.NAME).getValue() != null) {
source.parent((String) hit.field(ParentFieldMapper.NAME).getValue());
}
if (hit.field(TimestampFieldMapper.NAME).getValue() != null) {
source.timestamp((long) hit.field(TimestampFieldMapper.NAME).getValue());
}
long version = 0;
if (hit.field(VersionFieldMapper.NAME).getValue() != null) {
version = (long) hit.field(VersionFieldMapper.NAME).getValue();
}
Engine.Index indexOp = prepareIndex(docMapper(source.type()), source, version, VersionType.EXTERNAL_GTE, Engine.Operation.Origin.RECOVERY, state != IndexShardState.STARTED);
indexOp.setReindex(true);
index(indexOp);
}
}
}
示例3: createKeyToResultsAndFillOptimizationStructure
import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的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);
}
}
}
示例4: addUnmatchedResults
import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的package包/类
protected void addUnmatchedResults(List<InternalSearchHit> combinedResults, Collection<SearchHitsResult> firstTableSearchHits, List<Field> secondTableReturnedFields,int currentNumOfIds, int totalLimit,String t1Alias,String t2Alias) {
boolean limitReached = false;
for(SearchHitsResult hitsResult : firstTableSearchHits){
if(!hitsResult.isMatchedWithOtherTable())
for (InternalSearchHit hit : hitsResult.getSearchHits()) {
//todo: decide which id to put or type. or maby its ok this way. just need to doc.
InternalSearchHit unmachedResult = createUnmachedResult(secondTableReturnedFields, hit.docId(), t1Alias, t2Alias, hit);
combinedResults.add(unmachedResult);
currentNumOfIds++;
if (currentNumOfIds >= totalLimit) {
limitReached = true;
break;
}
}
if(limitReached) break;
}
}
示例5: mockClient
import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Client mockClient(List<Map<String, Object>> dataToReturn,
SearchRequestBuilder builder) {
Client client = mock(Client.class);
InternalSearchHit[] internalHitsArr = new InternalSearchHit[dataToReturn.size()];
for (int i = 0; i < dataToReturn.size(); i++) {
Map<String, Object> data = dataToReturn.get(i);
InternalSearchHit hit = mock(InternalSearchHit.class);
internalHitsArr[i] = hit;
when(hit.getSource()).thenReturn(data);
when(hit.getId()).thenReturn(Integer.toString(i));
}
InternalSearchHits hits = new InternalSearchHits(internalHitsArr, internalHitsArr.length,
0);
SearchResponse response = mock(SearchResponse.class);
when(response.getHits()).thenReturn(hits);
ListenableActionFuture<SearchResponse> action = mock(ListenableActionFuture.class);
when(builder.execute()).thenReturn(action);
when(builder.setQuery(any(QueryBuilder.class))).thenReturn(builder);
when(action.actionGet()).thenReturn(response);
when(client.prepareSearch(anyString())).thenReturn(builder);
return client;
}
示例6: buildAggregation
import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的package包/类
@Override
public InternalAggregation buildAggregation(long owningBucketOrdinal) {
TopDocsAndLeafCollector topDocsCollector = topDocsCollectors.get(owningBucketOrdinal);
final InternalTopHits topHits;
if (topDocsCollector == null) {
topHits = buildEmptyAggregation();
} else {
final TopDocs topDocs = topDocsCollector.topLevelCollector.topDocs();
subSearchContext.queryResult().topDocs(topDocs);
int[] docIdsToLoad = new int[topDocs.scoreDocs.length];
for (int i = 0; i < topDocs.scoreDocs.length; i++) {
docIdsToLoad[i] = topDocs.scoreDocs[i].doc;
}
subSearchContext.docIdsToLoad(docIdsToLoad, 0, docIdsToLoad.length);
fetchPhase.execute(subSearchContext);
FetchSearchResult fetchResult = subSearchContext.fetchResult();
InternalSearchHit[] internalHits = fetchResult.fetchResult().hits().internalHits();
for (int i = 0; i < internalHits.length; i++) {
ScoreDoc scoreDoc = topDocs.scoreDocs[i];
InternalSearchHit searchHitFields = internalHits[i];
searchHitFields.shard(subSearchContext.shardTarget());
searchHitFields.score(scoreDoc.score);
if (scoreDoc instanceof FieldDoc) {
FieldDoc fieldDoc = (FieldDoc) scoreDoc;
searchHitFields.sortValues(fieldDoc.fields);
}
}
topHits = new InternalTopHits(name, subSearchContext.from(), subSearchContext.size(), topDocs, fetchResult.hits(), pipelineAggregators(),
metaData());
}
return topHits;
}
示例7: insertIntoComparisonHash
import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的package包/类
public void insertIntoComparisonHash(String comparisonID,String comparisonKey,InternalSearchHit hit){
HashMap<String, SearchHitsResult> comparisonHash = this.comparisonIDtoComparisonHash.get(comparisonID);
SearchHitsResult currentSearchHitsResult = comparisonHash.get(comparisonKey);
if(currentSearchHitsResult == null) {
currentSearchHitsResult = new SearchHitsResult(new ArrayList<InternalSearchHit>(),false);
comparisonHash.put(comparisonKey, currentSearchHitsResult);
}
currentSearchHitsResult.getSearchHits().add(hit);
}
示例8: innerRun
import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的package包/类
public List<InternalSearchHit> innerRun() throws IOException, SqlParseException {
Map<String, Map<String, List<Object>>> optimizationTermsFilterStructure =
initOptimizationStructure();
updateFirstTableLimitIfNeeded();
TableInJoinRequestBuilder firstTableRequest = requestBuilder.getFirstTable();
createKeyToResultsAndFillOptimizationStructure(optimizationTermsFilterStructure, firstTableRequest);
TableInJoinRequestBuilder secondTableRequest = requestBuilder.getSecondTable();
if (needToOptimize(optimizationTermsFilterStructure)) {
updateRequestWithTermsFilter(optimizationTermsFilterStructure, secondTableRequest);
}
List<InternalSearchHit> combinedResult = createCombinedResults(secondTableRequest);
int currentNumOfResults = combinedResult.size();
int totalLimit = requestBuilder.getTotalLimit();
if (requestBuilder.getJoinType() == SQLJoinTableSource.JoinType.LEFT_OUTER_JOIN && currentNumOfResults < totalLimit) {
String t1Alias = requestBuilder.getFirstTable().getAlias();
String t2Alias = requestBuilder.getSecondTable().getAlias();
//todo: for each till Limit
addUnmatchedResults(combinedResult, this.hashJoinComparisonStructure.getAllSearchHits(),
requestBuilder.getSecondTable().getReturnedFields(),
currentNumOfResults, totalLimit,
t1Alias,
t2Alias);
}
if(firstTableRequest.getOriginalSelect().isOrderdSelect()){
Collections.sort(combinedResult,new Comparator<InternalSearchHit>() {
@Override
public int compare(InternalSearchHit o1, InternalSearchHit o2) {
return o1.docId() - o2.docId();
}
});
}
return combinedResult;
}
示例9: run
import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的package包/类
@Override
public void run() throws IOException, SqlParseException {
SearchResponse firstResponse = this.multiQueryBuilder.getFirstSearchRequest().get();
SearchHit[] hits = firstResponse.getHits().hits();
List<InternalSearchHit> unionHits = new ArrayList<>(hits.length);
fillInternalSearchHits(unionHits,hits,this.multiQueryBuilder.getFirstTableFieldToAlias());
SearchResponse secondResponse = this.multiQueryBuilder.getSecondSearchRequest().get();
fillInternalSearchHits(unionHits,secondResponse.getHits().hits(),this.multiQueryBuilder.getSecondTableFieldToAlias());
int totalSize = unionHits.size();
InternalSearchHit[] unionHitsArr = unionHits.toArray(new InternalSearchHit[totalSize]);
this.results = new InternalSearchHits(unionHitsArr, totalSize,1.0f);
}
示例10: run
import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的package包/类
public void run() throws IOException, SqlParseException {
long timeBefore = System.currentTimeMillis();
List<InternalSearchHit> combinedSearchHits = innerRun();
int resultsSize = combinedSearchHits.size();
InternalSearchHit[] hits = combinedSearchHits.toArray(new InternalSearchHit[resultsSize]);
this.results = new InternalSearchHits(hits, resultsSize,1.0f);
long joinTimeInMilli = System.currentTimeMillis() - timeBefore;
this.metaResults.setTookImMilli(joinTimeInMilli);
}
示例11: createUnmachedResult
import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的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;
}
示例12: combineResultsFromMultiResponses
import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的package包/类
private int combineResultsFromMultiResponses(List<InternalSearchHit> combinedResults, int totalLimit, int currentCombinedResults, SearchHit[] hits, int currentIndex, MultiSearchRequest multiSearchRequest) {
MultiSearchResponse.Item[] responses = client.multiSearch(multiSearchRequest).actionGet().getResponses();
String t1Alias = nestedLoopsRequest.getFirstTable().getAlias();
String t2Alias = nestedLoopsRequest.getSecondTable().getAlias();
for(int j =0 ; j < responses.length && currentCombinedResults < totalLimit ; j++){
SearchHit hitFromFirstTable = hits[currentIndex+j];
onlyReturnedFields(hitFromFirstTable.sourceAsMap(), nestedLoopsRequest.getFirstTable().getReturnedFields(),nestedLoopsRequest.getFirstTable().getOriginalSelect().isSelectAll());
SearchResponse multiItemResponse = responses[j].getResponse();
updateMetaSearchResults(multiItemResponse);
//todo: if responseForHit.getHits.length < responseForHit.getTotalHits(). need to fetch more!
SearchHits responseForHit = multiItemResponse.getHits();
if(responseForHit.getHits().length == 0 && nestedLoopsRequest.getJoinType() == SQLJoinTableSource.JoinType.LEFT_OUTER_JOIN){
InternalSearchHit unmachedResult = createUnmachedResult(nestedLoopsRequest.getSecondTable().getReturnedFields(), currentCombinedResults, t1Alias, t2Alias, hitFromFirstTable);
combinedResults.add(unmachedResult);
currentCombinedResults++;
continue;
}
for(SearchHit matchedHit : responseForHit.getHits() ){
InternalSearchHit searchHit = getMergedHit(currentCombinedResults, t1Alias, t2Alias, hitFromFirstTable, matchedHit);
combinedResults.add(searchHit);
currentCombinedResults++;
if(currentCombinedResults >= totalLimit) break;
}
if(currentCombinedResults >= totalLimit) break;
}
return currentCombinedResults;
}
示例13: getMergedHit
import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的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;
}
示例14: parseInternalSearchHits
import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private InternalSearchHits parseInternalSearchHits(Map<String, ?> map) {
// InternalSearchHits(InternalSearchHit[] hits, long totalHits, float maxScore)
InternalSearchHit[] internalSearchHits = parseInternalSearchHit();
Map<String, ?> internalMap = (Map<String, ?>) map.get(HITS);
long totalHits = internalMap != null && internalMap.containsKey(TOTAL) ? (Integer) internalMap.get(TOTAL) : -1L;
double maxScore = internalMap != null && internalMap.containsKey(MAXSCORE) ? (Double) internalMap.get(MAXSCORE) : 0.0f;
return new InternalSearchHits(internalSearchHits, totalHits, (float) maxScore);
}
示例15: search
import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的package包/类
@Override
public SearchResponse search(String searchTerms, List<String> references, List<String> siteIds, int start, int end, Map<String,String> additionalSearchInfromation) {
return new SearchResponse(
new InternalSearchResponse(new InternalSearchHits(new InternalSearchHit[0], 0, 0.0f), new InternalFacets(Collections.EMPTY_LIST), new InternalAggregations(Collections.EMPTY_LIST), new Suggest(), false, false),
"no-op",
1,
1,
1,
new ShardSearchFailure[0]
);
}