• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java InternalSearchHit类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.elasticsearch.search.internal.InternalSearchHit的典型用法代码示例。如果您正苦于以下问题:Java InternalSearchHit类的具体用法?Java InternalSearchHit怎么用?Java InternalSearchHit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



InternalSearchHit类属于org.elasticsearch.search.internal包,在下文中一共展示了InternalSearchHit类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
    );
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:19,代码来源:PercolateContext.java


示例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);
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:IndexShard.java


示例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);
        }
    }
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:23,代码来源:HashJoinElasticExecutor.java


示例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;
    }
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:20,代码来源:ElasticJoinExecutor.java


示例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;
}
 
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:27,代码来源:BaseProcessorTest.java


示例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;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:34,代码来源:TopHitsAggregator.java


示例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);
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:10,代码来源:HashJoinComparisonStructure.java


示例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;
    }
 
开发者ID:mazhou,项目名称:es-sql,代码行数:40,代码来源:HashJoinElasticExecutor.java


示例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);
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:13,代码来源:UnionExecutor.java


示例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);
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:10,代码来源:ElasticJoinExecutor.java


示例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;
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:16,代码来源:ElasticJoinExecutor.java


示例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;
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:34,代码来源:NestedLoopsElasticExecutor.java


示例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;
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:11,代码来源:NestedLoopsElasticExecutor.java


示例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);
}
 
开发者ID:jprante,项目名称:elasticsearch-client-http,代码行数:10,代码来源:HttpSearchAction.java


示例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]
    );
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:12,代码来源:ElasticSearchService.java


示例16: serialize

import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的package包/类
@Override
public JsonElement serialize(InternalSearchHit src, Type type, JsonSerializationContext jsonSerializationContext) {
    JsonObject hit = new JsonObject();
    hit.addProperty("_index", src.getIndex());
    hit.addProperty("_id", src.getId());
    hit.addProperty("_type", src.getType());
    hit.addProperty("_version", src.getVersion());
    JsonParser jsonParser = new JsonParser();
    hit.add("_source", jsonParser.parse((new GsonBuilder()).create().toJson(src.getSource())));
    return hit;
}
 
开发者ID:huangchaosuper,项目名称:toolkits,代码行数:12,代码来源:ElasticSearchElement.java


示例17: 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);
    map = (Map<String, ?>) map.get(HITS);
    long totalHits = map.containsKey(TOTAL) ? (Integer)map.get(TOTAL) : -1L;
    double maxScore = map.containsKey(MAXSCORE) ? (Double)map.get(MAXSCORE) : 0.0f;
    return new InternalSearchHits(internalSearchHits, totalHits, (float)maxScore);
}
 
开发者ID:jprante,项目名称:elasticsearch-helper,代码行数:10,代码来源:HttpSearchAction.java


示例18: parseInternalSearchHit

import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private InternalSearchHit[] parseInternalSearchHit(Map<String,?> map) {
    // public InternalSearchHit(int docId, String id, Text type, Map<String, SearchHitField> fields)
    List<InternalSearchHit> list = new LinkedList<>();
    Map<String,?> hitmap = (Map<String, ?>) map.get(HITS);
    List<Map<String,?>> hits = (List<Map<String, ?>>) hitmap.get(HITS);
    return list.toArray(new InternalSearchHit[list.size()]);
}
 
开发者ID:jprante,项目名称:elasticsearch-helper,代码行数:9,代码来源:HttpSearchAction.java


示例19: createNestedSearchHit

import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的package包/类
private InternalSearchHit createNestedSearchHit(SearchContext context, int nestedTopDocId, int nestedSubDocId, int rootSubDocId, List<String> extractFieldNames, boolean loadAllStored, Set<String> fieldNames, List<String> fieldNamePatterns, LeafReaderContext subReaderContext) throws IOException {
    // Also if highlighting is requested on nested documents we need to fetch the _source from the root document,
    // otherwise highlighting will attempt to fetch the _source from the nested doc, which will fail,
    // because the entire _source is only stored with the root document.
    final FieldsVisitor rootFieldsVisitor = new FieldsVisitor(context.sourceRequested() || extractFieldNames != null || context.highlight() != null);
    loadStoredFields(context, subReaderContext, rootFieldsVisitor, rootSubDocId);
    rootFieldsVisitor.postProcess(context.mapperService());

    Map<String, SearchHitField> searchFields = getSearchFields(context, nestedSubDocId, loadAllStored, fieldNames, fieldNamePatterns, subReaderContext);
    DocumentMapper documentMapper = context.mapperService().documentMapper(rootFieldsVisitor.uid().type());
    SourceLookup sourceLookup = context.lookup().source();
    sourceLookup.setSegmentAndDocument(subReaderContext, nestedSubDocId);

    ObjectMapper nestedObjectMapper = documentMapper.findNestedObjectMapper(nestedSubDocId, context, subReaderContext);
    assert nestedObjectMapper != null;
    InternalSearchHit.InternalNestedIdentity nestedIdentity = getInternalNestedIdentity(context, nestedSubDocId, subReaderContext, documentMapper, nestedObjectMapper);

    BytesReference source = rootFieldsVisitor.source();
    if (source != null) {
        Tuple<XContentType, Map<String, Object>> tuple = XContentHelper.convertToMap(source, true);
        Map<String, Object> sourceAsMap = tuple.v2();

        List<Map<String, Object>> nestedParsedSource;
        SearchHit.NestedIdentity nested = nestedIdentity;
        do {
            Object extractedValue = XContentMapValues.extractValue(nested.getField().string(), sourceAsMap);
            if (extractedValue == null) {
                // The nested objects may not exist in the _source, because it was filtered because of _source filtering
                break;
            } else if (extractedValue instanceof List) {
                // nested field has an array value in the _source
                nestedParsedSource = (List<Map<String, Object>>) extractedValue;
            } else if (extractedValue instanceof Map) {
                // nested field has an object value in the _source. This just means the nested field has just one inner object, which is valid, but uncommon.
                nestedParsedSource = Collections.singletonList((Map<String, Object>) extractedValue);
            } else {
                throw new IllegalStateException("extracted source isn't an object or an array");
            }
            sourceAsMap = nestedParsedSource.get(nested.getOffset());
            nested = nested.getChild();
        } while (nested != null);

        context.lookup().source().setSource(sourceAsMap);
        XContentType contentType = tuple.v1();
        BytesReference nestedSource = contentBuilder(contentType).map(sourceAsMap).bytes();
        context.lookup().source().setSource(nestedSource);
        context.lookup().source().setSourceContentType(contentType);
    }

    InternalSearchHit searchHit = new InternalSearchHit(nestedTopDocId, rootFieldsVisitor.uid().id(), documentMapper.typeText(), nestedIdentity, searchFields);
    if (extractFieldNames != null) {
        for (String extractFieldName : extractFieldNames) {
            List<Object> values = context.lookup().source().extractRawValues(extractFieldName);
            if (!values.isEmpty()) {
                if (searchHit.fieldsOrNull() == null) {
                    searchHit.fields(new HashMap<String, SearchHitField>(2));
                }

                SearchHitField hitField = searchHit.fields().get(extractFieldName);
                if (hitField == null) {
                    hitField = new InternalSearchHitField(extractFieldName, new ArrayList<>(2));
                    searchHit.fields().put(extractFieldName, hitField);
                }
                for (Object value : values) {
                    hitField.values().add(value);
                }
            }
        }
    }

    return searchHit;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:73,代码来源:FetchPhase.java


示例20: getInternalNestedIdentity

import org.elasticsearch.search.internal.InternalSearchHit; //导入依赖的package包/类
private InternalSearchHit.InternalNestedIdentity getInternalNestedIdentity(SearchContext context, int nestedSubDocId, LeafReaderContext subReaderContext, DocumentMapper documentMapper, ObjectMapper nestedObjectMapper) throws IOException {
    int currentParent = nestedSubDocId;
    ObjectMapper nestedParentObjectMapper;
    ObjectMapper current = nestedObjectMapper;
    String originalName = nestedObjectMapper.name();
    InternalSearchHit.InternalNestedIdentity nestedIdentity = null;
    do {
        Query parentFilter;
        nestedParentObjectMapper = documentMapper.findParentObjectMapper(current);
        if (nestedParentObjectMapper != null) {
            if (nestedParentObjectMapper.nested().isNested() == false) {
                current = nestedParentObjectMapper;
                continue;
            }
            parentFilter = nestedParentObjectMapper.nestedTypeFilter();
        } else {
            parentFilter = Queries.newNonNestedFilter();
        }

        Query childFilter = nestedObjectMapper.nestedTypeFilter();
        if (childFilter == null) {
            current = nestedParentObjectMapper;
            continue;
        }
        final Weight childWeight = context.searcher().createNormalizedWeight(childFilter, false);
        Scorer childScorer = childWeight.scorer(subReaderContext);
        if (childScorer == null) {
            current = nestedParentObjectMapper;
            continue;
        }
        DocIdSetIterator childIter = childScorer.iterator();

        BitSet parentBits = context.bitsetFilterCache().getBitSetProducer(parentFilter).getBitSet(subReaderContext);

        int offset = 0;
        int nextParent = parentBits.nextSetBit(currentParent);
        for (int docId = childIter.advance(currentParent + 1); docId < nextParent && docId != DocIdSetIterator.NO_MORE_DOCS; docId = childIter.nextDoc()) {
            offset++;
        }
        currentParent = nextParent;
        current = nestedObjectMapper = nestedParentObjectMapper;
        int currentPrefix = current == null ? 0 : current.name().length() + 1;
        nestedIdentity = new InternalSearchHit.InternalNestedIdentity(originalName.substring(currentPrefix), offset, nestedIdentity);
        if (current != null) {
            originalName = current.name();
        }
    } while (current != null);
    return nestedIdentity;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:50,代码来源:FetchPhase.java



注:本文中的org.elasticsearch.search.internal.InternalSearchHit类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AmbientLight类代码示例发布时间:2022-05-22
下一篇:
Java BadFencingConfigurationException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap