本文整理汇总了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));
}
示例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);
}
示例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));
}
示例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;
}
示例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;
}
示例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();
}
}
示例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);
}
});
}
}
示例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);
}
});
}
}