当前位置: 首页>>代码示例>>Java>>正文


Java MultiGetRequest.add方法代码示例

本文整理汇总了Java中org.elasticsearch.action.get.MultiGetRequest.add方法的典型用法代码示例。如果您正苦于以下问题:Java MultiGetRequest.add方法的具体用法?Java MultiGetRequest.add怎么用?Java MultiGetRequest.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.action.get.MultiGetRequest的用法示例。


在下文中一共展示了MultiGetRequest.add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepareRequest

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
    multiGetRequest.preference(request.param("preference"));
    multiGetRequest.realtime(request.paramAsBoolean("realtime", multiGetRequest.realtime()));
    if (request.param("fields") != null) {
        throw new IllegalArgumentException("The parameter [fields] is no longer supported, " +
            "please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored");
    }
    String[] sFields = null;
    String sField = request.param("stored_fields");
    if (sField != null) {
        sFields = Strings.splitStringByCommaToArray(sField);
    }

    FetchSourceContext defaultFetchSource = FetchSourceContext.parseFromRestRequest(request);
    try (XContentParser parser = request.contentOrSourceParamParser()) {
        multiGetRequest.add(request.param("index"), request.param("type"), sFields, defaultFetchSource,
            request.param("routing"), parser, allowExplicitIndex);
    }

    return channel -> client.multiGet(multiGetRequest, new RestToXContentListener<>(channel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:RestMultiGetAction.java

示例2: testMultiGet

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
public void testMultiGet() {
    String multiGetShardAction = MultiGetAction.NAME + "[shard][s]";
    interceptTransportActions(multiGetShardAction);

    List<String> indices = new ArrayList<>();
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    int numDocs = iterations(1, 30);
    for (int i = 0; i < numDocs; i++) {
        String indexOrAlias = randomIndexOrAlias();
        multiGetRequest.add(indexOrAlias, "type", Integer.toString(i));
        indices.add(indexOrAlias);
    }
    internalCluster().coordOnlyNodeClient().multiGet(multiGetRequest).actionGet();

    clearInterceptedActions();
    assertIndicesSubset(indices, multiGetShardAction);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:IndicesRequestIT.java

示例3: handleRequest

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
    multiGetRequest.preference(request.param("preference"));
    multiGetRequest.realtime(request.paramAsBoolean("realtime", null));
    multiGetRequest.ignoreErrorsOnGeneratedFields(request.paramAsBoolean("ignore_errors_on_generated_fields", false));

    String[] sFields = null;
    String sField = request.param("fields");
    if (sField != null) {
        sFields = Strings.splitStringByCommaToArray(sField);
    }

    FetchSourceContext defaultFetchSource = FetchSourceContext.parseFromRestRequest(request);
    multiGetRequest.add(request.param("index"), request.param("type"), sFields, defaultFetchSource, request.param("routing"), RestActions.getRestContent(request), allowExplicitIndex);

    client.multiGet(multiGetRequest, new RestToXContentListener<MultiGetResponse>(channel));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:20,代码来源:RestMultiGetAction.java

示例4: toMultiGetRequest

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
@Converter
public static MultiGetRequest toMultiGetRequest(Object document, Exchange exchange) {
    List<Item> items = (List<Item>) document;
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    Iterator<Item> it = items.iterator();
    while (it.hasNext()) {
        MultiGetRequest.Item item = it.next();
        multiGetRequest.add(item);
    }
    return multiGetRequest;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:ElasticsearchActionRequestConverter.java

示例5: toMultiSearchRequest

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
protected MultiSearchRequest toMultiSearchRequest(final RestRequest request) throws Exception {

        final MultiGetRequest multiGetRequest = new MultiGetRequest();
        multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
        multiGetRequest.preference(request.param("preference"));
        multiGetRequest.realtime(request.paramAsBoolean("realtime", null));
        multiGetRequest.ignoreErrorsOnGeneratedFields(request.paramAsBoolean("ignore_errors_on_generated_fields", false));

        String[] sFields = null;
        final String sField = request.param("fields");
        if (sField != null) {
            sFields = Strings.splitStringByCommaToArray(sField);
        }

        final FetchSourceContext defaultFetchSource = FetchSourceContext.parseFromRestRequest(request);
        multiGetRequest.add(request.param("index"), request.param("type"), sFields, defaultFetchSource, request.param("routing"),
                RestActions.getRestContent(request),
                settings.getAsBoolean(AbstractACRestFilter.REST_ACTION_MULTI_ALLOW_EXPLICIT_INDEX, true));

        final MultiSearchRequest msearch = new MultiSearchRequest();
        msearch.copyContextFrom(request);

        for (final Iterator<Item> iterator = multiGetRequest.iterator(); iterator.hasNext();) {
            final Item item = iterator.next();

            final SearchRequest st = new SearchRequest();
            st.routing(item.routing());
            st.indices(item.indices());
            st.types(item.type());
            st.preference(request.param("preference"));
            st.source(SearchSourceBuilder.searchSource().query(new IdsQueryBuilder(item.type()).addIds(item.id())));
            msearch.add(st);
        }

        return msearch;

    }
 
开发者ID:petalmd,项目名称:armor,代码行数:38,代码来源:AbstractACRestFilter.java

示例6: syncAcl

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
private void syncAcl(OpenshiftRequestContext context) {
    LOGGER.debug("Syncing the ACL to ElasticSearch");
    try {
        lock.lock();
        LOGGER.debug("Loading SearchGuard ACL...");

        final MultiGetRequest mget = new MultiGetRequest();
        mget.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true"); //header needed here
        mget.refresh(true);
        mget.realtime(true);
        mget.add(searchGuardIndex, SEARCHGUARD_ROLE_TYPE, SEARCHGUARD_CONFIG_ID);
        mget.add(searchGuardIndex, SEARCHGUARD_MAPPING_TYPE, SEARCHGUARD_CONFIG_ID);

        SearchGuardRoles roles = null;
        SearchGuardRolesMapping rolesMapping = null;
        MultiGetResponse response = client.multiGet(mget).actionGet();
        for (MultiGetItemResponse item : response.getResponses()) {
            if(!item.isFailed()) {
                if(LOGGER.isDebugEnabled()){
                    LOGGER.debug("Read in {}: {}", item.getType(), XContentHelper.convertToJson(item.getResponse().getSourceAsBytesRef(), true, true));
                }
                switch (item.getType()) {
                case SEARCHGUARD_ROLE_TYPE:
                    roles = new SearchGuardRoles().load(item.getResponse().getSource());
                    break;
                case SEARCHGUARD_MAPPING_TYPE:
                    rolesMapping = new SearchGuardRolesMapping().load(item.getResponse().getSource());
                    break;
                }
            }else {
                LOGGER.error("There was a failure loading document type {}", item.getFailure(), item.getType());
            }
        }

        if(roles == null || rolesMapping == null) {
            return;
        }

        LOGGER.debug("Syncing from cache to ACL...");
        RolesMappingSyncStrategy rolesMappingSync = documentFactory.createRolesMappingSyncStrategy(rolesMapping);
        rolesMappingSync.syncFrom(cache);
        
        RolesSyncStrategy rolesSync = documentFactory.createRolesSyncStrategy(roles);
        rolesSync.syncFrom(cache);

        writeAcl(roles, rolesMapping);
    } catch (Exception e) {
        LOGGER.error("Exception while syncing ACL with cache", e);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:fabric8io,项目名称:openshift-elasticsearch-plugin,代码行数:53,代码来源:DynamicACLFilter.java

示例7: loadAsync

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
void loadAsync(final String[] events, final ConfigCallback callback) {        
    if(events == null || events.length == 0) {
        log.warn("No config events requested to load");
        return;
    }
    
    final MultiGetRequest mget = new MultiGetRequest();

    for (int i = 0; i < events.length; i++) {
        final String event = events[i];
        mget.add(searchguardIndex, "sg", event);
    }
    
    mget.refresh(true);
    mget.realtime(true);
    
    //try(StoredContext ctx = threadContext.stashContext()) {
    //    threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true");
    {
        client.multiGet(mget, new ActionListener<MultiGetResponse>() {
            @Override
            public void onResponse(MultiGetResponse response) {
                MultiGetItemResponse[] responses = response.getResponses();
                for (int i = 0; i < responses.length; i++) {
                    MultiGetItemResponse singleResponse = responses[i];
                    if(singleResponse != null && !singleResponse.isFailed()) {
                        GetResponse singleGetResponse = singleResponse.getResponse();
                        if(singleGetResponse.isExists() && !singleGetResponse.isSourceEmpty()) {
                            //success
                            final Settings _settings = toSettings(singleGetResponse.getSourceAsBytesRef(), singleGetResponse.getId());
                            if(_settings != null) {
                                callback.success(singleGetResponse.getId(), _settings);
                            } else {
                                log.error("Cannot parse settings for "+singleGetResponse.getId());
                            }
                        } else {
                            //does not exist or empty source
                            callback.noData(singleGetResponse.getId());
                        }
                    } else {
                        //failure
                        callback.singleFailure(singleResponse==null?null:singleResponse.getFailure());
                    }
                }
            }           
            
            @Override
            public void onFailure(Exception e) {
                callback.failure(e);
            }
        });
    }
}
 
开发者ID:floragunncom,项目名称:search-guard,代码行数:54,代码来源:ConfigurationLoader.java

示例8: loadAsyncLegacy

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
void loadAsyncLegacy(final String[] events, final ConfigCallback callback) {        
    if(events == null || events.length == 0) {
        log.warn("No config events requested to load");
        return;
    }
    
    final MultiGetRequest mget = new MultiGetRequest();

    for (int i = 0; i < events.length; i++) {
        final String event = events[i];
        mget.add(searchguardIndex, event, "0");
    }
    
    mget.refresh(true);
    mget.realtime(true);
    
    //try(StoredContext ctx = threadContext.stashContext()) {
      //  threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true");
        {
        client.multiGet(mget, new ActionListener<MultiGetResponse>() {
            @Override
            public void onResponse(MultiGetResponse response) {
                MultiGetItemResponse[] responses = response.getResponses();
                for (int i = 0; i < responses.length; i++) {
                    MultiGetItemResponse singleResponse = responses[i];
                    if(singleResponse != null && !singleResponse.isFailed()) {
                        GetResponse singleGetResponse = singleResponse.getResponse();
                        if(singleGetResponse.isExists() && !singleGetResponse.isSourceEmpty()) {
                            //success
                            final Settings _settings = toSettings(singleGetResponse.getSourceAsBytesRef(), singleGetResponse.getType());
                            if(_settings != null) {
                                callback.success(singleGetResponse.getType(), _settings);
                            } else {
                                log.error("Cannot parse settings for "+singleGetResponse.getType());
                            }
                        } else {
                            //does not exist or empty source
                            callback.noData(singleGetResponse.getType());
                        }
                    } else {
                        //failure
                        callback.singleFailure(singleResponse==null?null:singleResponse.getFailure());
                    }
                }
            }           
            
            @Override
            public void onFailure(Exception e) {
                callback.failure(e);
            }
        });
    }
}
 
开发者ID:floragunncom,项目名称:search-guard,代码行数:54,代码来源:LegacyConfigurationLoader.java


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