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

Java Params类代码示例

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

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



Params类属于org.elasticsearch.common.xcontent.ToXContent包,在下文中一共展示了Params类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: buildBroadcastShardsHeader

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
public static void buildBroadcastShardsHeader(XContentBuilder builder, Params params,
                                              int total, int successful, int failed,
                                              ShardOperationFailedException[] shardFailures) throws IOException {
    builder.startObject("_shards");
    builder.field("total", total);
    builder.field("successful", successful);
    builder.field("failed", failed);
    if (shardFailures != null && shardFailures.length > 0) {
        builder.startArray("failures");
        final boolean group = params.paramAsBoolean("group_shard_failures", true); // we group by default
        for (ShardOperationFailedException shardFailure : group ? ExceptionsHelper.groupBy(shardFailures) : shardFailures) {
            builder.startObject();
            shardFailure.toXContent(builder, params);
            builder.endObject();
        }
        builder.endArray();
    }
    builder.endObject();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:RestActions.java


示例2: buildNodesHeader

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
/**
 * Create the XContent header for any {@link BaseNodesResponse}. This looks like:
 * <code>
 * "_nodes" : {
 *   "total" : 3,
 *   "successful" : 1,
 *   "failed" : 2,
 *   "failures" : [ { ... }, { ... } ]
 * }
 * </code>
 * Prefer the overload that properly invokes this method to calling this directly.
 *
 * @param builder XContent builder.
 * @param params XContent parameters.
 * @param total The total number of nodes touched.
 * @param successful The successful number of responses received.
 * @param failed The number of failures (effectively {@code total - successful}).
 * @param failures The failure exceptions related to {@code failed}.
 * @see #buildNodesHeader(XContentBuilder, Params, BaseNodesResponse)
 */
public static void buildNodesHeader(final XContentBuilder builder, final Params params,
                                    final int total, final int successful, final int failed,
                                    final List<FailedNodeException> failures) throws IOException {
    builder.startObject("_nodes");
    builder.field("total", total);
    builder.field("successful", successful);
    builder.field("failed", failed);

    if (failures.isEmpty() == false) {
        builder.startArray("failures");
        for (FailedNodeException failure : failures) {
            builder.startObject();
            failure.toXContent(builder, params);
            builder.endObject();
        }
        builder.endArray();
    }

    builder.endObject();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:RestActions.java


示例3: filterSettings

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
public static Settings filterSettings(Params params, Settings settings) {
    String patterns = params.param(SETTINGS_FILTER_PARAM);
    final Settings filteredSettings;
    if (patterns != null && patterns.isEmpty() == false) {
        filteredSettings = filterSettings(Strings.commaDelimitedListToSet(patterns), settings);
    } else {
        filteredSettings = settings;
    }
    return filteredSettings;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:SettingsFilter.java


示例4: writeRawField

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
/**
 * Writes a "raw" (bytes) field, handling cases where the bytes are compressed, and tries to optimize writing using
 * {@link XContentBuilder#rawField(String, org.elasticsearch.common.bytes.BytesReference)}.
 * @deprecated use {@link #writeRawField(String, BytesReference, XContentType, XContentBuilder, Params)} to avoid content type
 * auto-detection
 */
@Deprecated
public static void writeRawField(String field, BytesReference source, XContentBuilder builder, ToXContent.Params params) throws IOException {
    Compressor compressor = CompressorFactory.compressor(source);
    if (compressor != null) {
        InputStream compressedStreamInput = compressor.streamInput(source.streamInput());
        builder.rawField(field, compressedStreamInput);
    } else {
        builder.rawField(field, source);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:XContentHelper.java


示例5: filterSettings

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
public static Settings filterSettings(Params params, Settings settings) {
    String patterns = params.param(SETTINGS_FILTER_PARAM);
    Settings filteredSettings = settings;
    if (patterns != null && patterns.isEmpty() == false) {
        filteredSettings = SettingsFilter.filterSettings(patterns, filteredSettings);
    }
    return filteredSettings;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:9,代码来源:SettingsFilter.java


示例6: writeRawField

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
/**
 * Writes a "raw" (bytes) field, handling cases where the bytes are compressed, and tries to optimize writing using
 * {@link XContentBuilder#rawField(String, org.elasticsearch.common.bytes.BytesReference)}.
 */
public static void writeRawField(String field, BytesReference source, XContentBuilder builder, ToXContent.Params params) throws IOException {
    Compressor compressor = CompressorFactory.compressor(source);
    if (compressor != null) {
        InputStream compressedStreamInput = compressor.streamInput(source.streamInput());
        builder.rawField(field, compressedStreamInput);
    } else {
        builder.rawField(field, source);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:14,代码来源:XContentHelper.java


示例7: toXContent

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
void toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    builder.field(CommonFields.KEY, term);
    builder.field(CommonFields.DOC_COUNT, count);
    aggregations.toXContentInternal(builder, params);
    builder.endObject();
}
 
开发者ID:algolia,项目名称:elasticsearch-topk-plugin,代码行数:8,代码来源:TopK.java


示例8: execute

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
/**
 * Execute the reindexing
 *
 * @param params   Rest request
 * @param content  Content of rest request in {}
 * @param listener is to receive the response back
 * @return
 */
public String execute(final Params params, final BytesReference content, final ActionListener<Void> listener) {

    final String url = params.param("url");
    // set scroll to 1m if there is no
    final String scroll = params.param("scroll", "1m");
    final String fromIndex = params.param("index");
    final String fromType = params.param("type");
    final String toIndex = params.param("toindex");
    final String toType = params.param("totype");
    final String[] fields = params.paramAsBoolean("parent", true) ? new String[]{"_source", "_parent"} : new String[]{"_source"};
    final boolean deletion = params.paramAsBoolean("deletion", false);

    final ReindexingListener reindexingListener = new ReindexingListener(url, fromIndex, fromType, toIndex, toType, scroll, deletion, listener);

    // Create search request builder
    final SearchRequestBuilder builder = client.prepareSearch(fromIndex)
            .setScroll(scroll).addFields(fields);
    if (fromType != null && fromType.trim().length() > 0) {
        builder.setTypes(fromType.split(","));
    }
    if (content == null || content.length() == 0) {
        builder.setQuery(QueryBuilders.matchAllQuery()).setSize(
                Integer.parseInt(params.param("size", "1000")));
    } else {
        builder.setExtraSource(content);
    }
    builder.execute(reindexingListener);  // async
    reindexingListenerMap.put(reindexingListener.getName(), reindexingListener);
    return reindexingListener.getName();
}
 
开发者ID:codelibs,项目名称:elasticsearch-reindexing,代码行数:39,代码来源:ReindexingService.java


示例9: execute

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
public void execute(final Params params,
        final RequestHandler.OnErrorListener listener,
        final Map<String, Object> requestMap,
        final Map<String, Object> paramMap) {
    synchronized (handlers) {
        if (position < handlers.length) {
            final RequestHandler handler = handlers[position];
            position++;
            handler.execute(params, listener, requestMap, paramMap, this);
        }
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-taste,代码行数:13,代码来源:RequestHandlerChain.java


示例10: doItemIndexExists

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
private void doItemIndexExists(final Params params,
        final RequestHandler.OnErrorListener listener,
        final Map<String, Object> requestMap,
        final Map<String, Object> paramMap, final RequestHandlerChain chain) {
    final String index = params.param(
            TasteConstants.REQUEST_PARAM_ITEM_INDEX, params.param("index"));

    try {
        indexCreationLock.lock();
        final IndicesExistsResponse indicesExistsResponse = client.admin()
                .indices().prepareExists(index).execute().actionGet();
        if (indicesExistsResponse.isExists()) {
            doItemMappingCreation(params, listener, requestMap, paramMap,
                    chain);
        } else {
            doItemIndexCreation(params, listener, requestMap, paramMap,
                    chain, index);
        }
    } catch (final Exception e) {
        final List<Throwable> errorList = getErrorList(paramMap);
        if (errorList.size() >= maxRetryCount) {
            listener.onError(e);
        } else {
            sleep(e);
            errorList.add(e);
            fork(() -> execute(params, listener, requestMap, paramMap,
                    chain));
        }
    } finally {
        indexCreationLock.unlock();
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-taste,代码行数:33,代码来源:ItemRequestHandler.java


示例11: doItemUpdate

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
private void doItemUpdate(final Params params,
        final RequestHandler.OnErrorListener listener,
        final Map<String, Object> requestMap,
        final Map<String, Object> paramMap,
        final Map<String, Object> itemMap, final String index,
        final String type, final String itemIdField,
        final String timestampField, final Long itemId,
        final OpType opType, final RequestHandlerChain chain) {
    itemMap.put(itemIdField, itemId);
    itemMap.put(timestampField, new Date());
    final OnResponseListener<IndexResponse> responseListener = response -> {
        paramMap.put(itemIdField, itemId);
        chain.execute(params, listener, requestMap, paramMap);
    };
    final OnFailureListener failureListener = t -> {
        sleep(t);
        if (t instanceof DocumentAlreadyExistsException
                || t instanceof EsRejectedExecutionException) {
            execute(params, listener, requestMap, paramMap, chain);
        } else {
            listener.onError(t);
        }
    };
    client.prepareIndex(index, type, itemId.toString()).setSource(itemMap)
            .setRefresh(true).setOpType(opType)
            .execute(on(responseListener, failureListener));
}
 
开发者ID:codelibs,项目名称:elasticsearch-taste,代码行数:28,代码来源:ItemRequestHandler.java


示例12: doPreferenceIndexExists

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
private void doPreferenceIndexExists(final Params params,
        final RequestHandler.OnErrorListener listener,
        final Map<String, Object> requestMap,
        final Map<String, Object> paramMap, final RequestHandlerChain chain) {
    final String index = params.param("index");

    try {
        indexCreationLock.lock();
        final IndicesExistsResponse indicesExistsResponse = client.admin()
                .indices().prepareExists(index).execute().actionGet();
        if (indicesExistsResponse.isExists()) {
            doPreferenceMappingCreation(params, listener, requestMap,
                    paramMap, chain);
        } else {
            doPreferenceIndexCreation(params, listener, requestMap,
                    paramMap, chain, index);
        }
    } catch (final Exception e) {
        final List<Throwable> errorList = getErrorList(paramMap);
        if (errorList.size() >= maxRetryCount) {
            listener.onError(e);
        } else {
            sleep(e);
            errorList.add(e);
            fork(() -> execute(params, listener, requestMap, paramMap,
                    chain));
        }
    } finally {
        indexCreationLock.unlock();
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-taste,代码行数:32,代码来源:PreferenceRequestHandler.java


示例13: MultiTermVectorsListener

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
public MultiTermVectorsListener(final int numOfThread,
        final RequestHandler[] requestHandlers,
        final Params eventParams, final Map<String, DocInfo> idMap,
        final ExecutorService executor, final ESLogger logger) {
    this.requestHandlers = requestHandlers;
    this.eventParams = eventParams;
    this.idMap = idMap;
    this.executor = executor;
    this.logger = logger;
    this.numOfThread = numOfThread > 1 ? numOfThread : 1;
}
 
开发者ID:codelibs,项目名称:elasticsearch-taste,代码行数:12,代码来源:GenTermValuesHandler.java


示例14: doUserIndexExists

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
private void doUserIndexExists(final Params params,
        final RequestHandler.OnErrorListener listener,
        final Map<String, Object> requestMap,
        final Map<String, Object> paramMap, final RequestHandlerChain chain) {
    final String index = params.param(
            TasteConstants.REQUEST_PARAM_USER_INDEX, params.param("index"));

    try {
        indexCreationLock.lock();
        final IndicesExistsResponse indicesExistsResponse = client.admin()
                .indices().prepareExists(index).execute().actionGet();
        if (indicesExistsResponse.isExists()) {
            doUserMappingCreation(params, listener, requestMap, paramMap,
                    chain);
        } else {
            doUserIndexCreation(params, listener, requestMap, paramMap,
                    chain, index);
        }
    } catch (final Exception e) {
        final List<Throwable> errorList = getErrorList(paramMap);
        if (errorList.size() >= maxRetryCount) {
            listener.onError(e);
        } else {
            sleep(e);
            errorList.add(e);
            fork(() -> execute(params, listener, requestMap, paramMap,
                    chain));
        }
    } finally {
        indexCreationLock.unlock();
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-taste,代码行数:33,代码来源:UserRequestHandler.java


示例15: doUserUpdate

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
private void doUserUpdate(final Params params,
        final RequestHandler.OnErrorListener listener,
        final Map<String, Object> requestMap,
        final Map<String, Object> paramMap,
        final Map<String, Object> userMap, final String index,
        final String type, final String userIdField,
        final String timestampField, final Long userId,
        final OpType opType, final RequestHandlerChain chain) {
    userMap.put(userIdField, userId);
    userMap.put(timestampField, new Date());

    final OnResponseListener<IndexResponse> responseListener = response -> {
        paramMap.put(userIdField, userId);
        chain.execute(params, listener, requestMap, paramMap);
    };
    final OnFailureListener failureListener = t -> {
        if (t instanceof DocumentAlreadyExistsException
                || t instanceof EsRejectedExecutionException) {
            sleep(t);
            execute(params, listener, requestMap, paramMap, chain);
        } else {
            listener.onError(t);
        }
    };
    client.prepareIndex(index, type, userId.toString()).setSource(userMap)
            .setRefresh(true).setOpType(opType)
            .execute(on(responseListener, failureListener));
}
 
开发者ID:codelibs,项目名称:elasticsearch-taste,代码行数:29,代码来源:UserRequestHandler.java


示例16: doItemMappingCreation

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
private void doItemMappingCreation(final Params params,
        final RequestHandler.OnErrorListener listener,
        final Map<String, Object> requestMap,
        final Map<String, Object> paramMap, final RequestHandlerChain chain) {
    final String index = params.param(
            TasteConstants.REQUEST_PARAM_ITEM_INDEX, params.param("index"));
    final String type = params.param(
            TasteConstants.REQUEST_PARAM_ITEM_TYPE,
            TasteConstants.ITEM_TYPE);
    final String itemIdField = params.param(
            TasteConstants.REQUEST_PARAM_ITEM_ID_FIELD,
            TasteConstants.ITEM_ID_FIELD);
    final String timestampField = params.param(
            TasteConstants.REQUEST_PARAM_TIMESTAMP_FIELD,
            TasteConstants.TIMESTAMP_FIELD);

    try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
        final ClusterHealthResponse healthResponse = client
                .admin()
                .cluster()
                .prepareHealth(index)
                .setWaitForYellowStatus()
                .setTimeout(
                        params.param("timeout",
                                DEFAULT_HEALTH_REQUEST_TIMEOUT)).execute()
                .actionGet();
        if (healthResponse.isTimedOut()) {
            listener.onError(new OperationFailedException(
                    "Failed to create index: " + index + "/" + type));
        }

        final XContentBuilder builder = jsonBuilder//
                .startObject()//
                .startObject(type)//
                .startObject("properties")//

                // @timestamp
                .startObject(timestampField)//
                .field("type", "date")//
                .field("format", "date_optional_time")//
                .endObject()//

                // item_id
                .startObject(itemIdField)//
                .field("type", "long")//
                .endObject()//

                // system_id
                .startObject("system_id")//
                .field("type", "string")//
                .field("index", "not_analyzed")//
                .endObject()//

                .endObject()//
                .endObject()//
                .endObject();

        final PutMappingResponse mappingResponse = client.admin().indices()
                .preparePutMapping(index).setType(type).setSource(builder)
                .execute().actionGet();
        if (mappingResponse.isAcknowledged()) {
            fork(() -> execute(params, listener, requestMap, paramMap,
                    chain));
        } else {
            listener.onError(new OperationFailedException(
                    "Failed to create mapping for " + index + "/" + type));
        }
    } catch (final Exception e) {
        listener.onError(e);
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-taste,代码行数:72,代码来源:ItemRequestHandler.java


示例17: doItemCreation

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
private void doItemCreation(final Params params,
        final RequestHandler.OnErrorListener listener,
        final Map<String, Object> requestMap,
        final Map<String, Object> paramMap,
        final Map<String, Object> itemMap, final String index,
        final String type, final String itemIdField,
        final String timestampField, final RequestHandlerChain chain) {
    final OnResponseListener<SearchResponse> responseListener = response -> {
        validateRespose(response);

        Number currentId = null;
        final SearchHits hits = response.getHits();
        if (hits.getTotalHits() != 0) {
            final SearchHit[] searchHits = hits.getHits();
            final SearchHitField field = searchHits[0].getFields().get(
                    itemIdField);
            if (field != null) {
                currentId = field.getValue();
            }
        }
        final Long itemId;
        if (currentId == null) {
            itemId = Long.valueOf(1);
        } else {
            itemId = Long.valueOf(currentId.longValue() + 1);
        }
        doItemUpdate(params, listener, requestMap, paramMap, itemMap,
                index, type, itemIdField, timestampField, itemId,
                OpType.CREATE, chain);
    };
    final OnFailureListener failureListener = t -> {
        final List<Throwable> errorList = getErrorList(paramMap);
        if (errorList.size() >= maxRetryCount) {
            listener.onError(t);
        } else {
            sleep(t);
            errorList.add(t);
            doItemIndexExists(params, listener, requestMap, paramMap,
                    chain);
        }
    };
    client.prepareSearch(index).setTypes(type)
            .setQuery(QueryBuilders.matchAllQuery()).addField(itemIdField)
            .addSort(itemIdField, SortOrder.DESC).setSize(1)
            .execute(on(responseListener, failureListener));
}
 
开发者ID:codelibs,项目名称:elasticsearch-taste,代码行数:47,代码来源:ItemRequestHandler.java


示例18: doPreferenceMappingCreation

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
private void doPreferenceMappingCreation(final Params params,
        final RequestHandler.OnErrorListener listener,
        final Map<String, Object> requestMap,
        final Map<String, Object> paramMap, final RequestHandlerChain chain) {
    final String index = params.param("index");
    final String type = params
            .param("type", TasteConstants.PREFERENCE_TYPE);
    final String userIdField = params.param(
            TasteConstants.REQUEST_PARAM_USER_ID_FIELD,
            TasteConstants.USER_ID_FIELD);
    final String itemIdField = params.param(
            TasteConstants.REQUEST_PARAM_ITEM_ID_FIELD,
            TasteConstants.ITEM_ID_FIELD);
    final String valueField = params.param(
            TasteConstants.REQUEST_PARAM_VALUE_FIELD,
            TasteConstants.VALUE_FIELD);
    final String timestampField = params.param(
            TasteConstants.REQUEST_PARAM_TIMESTAMP_FIELD,
            TasteConstants.TIMESTAMP_FIELD);

    try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
        final ClusterHealthResponse healthResponse = client
                .admin()
                .cluster()
                .prepareHealth(index)
                .setWaitForYellowStatus()
                .setTimeout(
                        params.param("timeout",
                                DEFAULT_HEALTH_REQUEST_TIMEOUT)).execute()
                .actionGet();
        if (healthResponse.isTimedOut()) {
            listener.onError(new OperationFailedException(
                    "Failed to create index: " + index + "/" + type));
        }

        final XContentBuilder builder = jsonBuilder//
                .startObject()//
                .startObject(type)//
                .startObject("properties")//

                // @timestamp
                .startObject(timestampField)//
                .field("type", "date")//
                .field("format", "date_optional_time")//
                .endObject()//

                // user_id
                .startObject(userIdField)//
                .field("type", "long")//
                .endObject()//

                // item_id
                .startObject(itemIdField)//
                .field("type", "long")//
                .endObject()//

                // value
                .startObject(valueField)//
                .field("type", "double")//
                .endObject()//

                .endObject()//
                .endObject()//
                .endObject();

        final PutMappingResponse mappingResponse = client.admin().indices()
                .preparePutMapping(index).setType(type).setSource(builder)
                .execute().actionGet();
        if (mappingResponse.isAcknowledged()) {
            fork(() -> execute(params, listener, requestMap, paramMap,
                    chain));
        } else {
            listener.onError(new OperationFailedException(
                    "Failed to create mapping for " + index + "/" + type));
        }
    } catch (final Exception e) {
        listener.onError(e);
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-taste,代码行数:80,代码来源:PreferenceRequestHandler.java


示例19: execute

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
@Override
public abstract void execute(final Params params,
        final RequestHandler.OnErrorListener listener,
        final Map<String, Object> requestMap,
        final Map<String, Object> paramMap, RequestHandlerChain chain);
 
开发者ID:codelibs,项目名称:elasticsearch-taste,代码行数:6,代码来源:DefaultRequestHandler.java


示例20: doUserMappingCreation

import org.elasticsearch.common.xcontent.ToXContent.Params; //导入依赖的package包/类
private void doUserMappingCreation(final Params params,
        final RequestHandler.OnErrorListener listener,
        final Map<String, Object> requestMap,
        final Map<String, Object> paramMap, final RequestHandlerChain chain) {
    final String index = params.param(
            TasteConstants.REQUEST_PARAM_USER_INDEX, params.param("index"));
    final String type = params.param(
            TasteConstants.REQUEST_PARAM_USER_TYPE,
            TasteConstants.USER_TYPE);
    final String userIdField = params.param(
            TasteConstants.REQUEST_PARAM_USER_ID_FIELD,
            TasteConstants.USER_ID_FIELD);
    final String timestampField = params.param(
            TasteConstants.REQUEST_PARAM_TIMESTAMP_FIELD,
            TasteConstants.TIMESTAMP_FIELD);

    try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
        final ClusterHealthResponse healthResponse = client
                .admin()
                .cluster()
                .prepareHealth(index)
                .setWaitForYellowStatus()
                .setTimeout(
                        params.param("timeout",
                                DEFAULT_HEALTH_REQUEST_TIMEOUT)).execute()
                .actionGet();
        if (healthResponse.isTimedOut()) {
            listener.onError(new OperationFailedException(
                    "Failed to create index: " + index + "/" + type));
        }

        final XContentBuilder builder = jsonBuilder//
                .startObject()//
                .startObject(type)//
                .startObject("properties")//

                // @timestamp
                .startObject(timestampField)//
                .field("type", "date")//
                .field("format", "date_optional_time")//
                .endObject()//

                // user_id
                .startObject(userIdField)//
                .field("type", "long")//
                .endObject()//

                // system_id
                .startObject("system_id")//
                .field("type", "string")//
                .field("index", "not_analyzed")//
                .endObject()//

                .endObject()//
                .endObject()//
                .endObject();

        final PutMappingResponse mappingResponse = client.admin().indices()
                .preparePutMapping(index).setType(type).setSource(builder)
                .execute().actionGet();
        if (mappingResponse.isAcknowledged()) {
            fork(() -> execute(params, listener, requestMap, paramMap,
                    chain));
        } else {
            listener.onError(new OperationFailedException(
                    "Failed to create mapping for " + index + "/" + type));
        }
    } catch (final Exception e) {
        listener.onError(e);
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-taste,代码行数:72,代码来源:UserRequestHandler.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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