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


Java CreateIndexRequestBuilder类代码示例

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


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

示例1: initIndexIfNotExists

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; //导入依赖的package包/类
/**
 * Init index setting and mapping.
 *
 * @return true if a new index was created, false otherwise
 */
public boolean initIndexIfNotExists() throws IOException {
  final IndicesExistsResponse existsResponse = esClient.admin().indices().prepareExists(INDEX).get();
  if (existsResponse.isExists()) {
    return false;
  }
  final String settings = Resources.toString(
      getClass().getResource("/elasticsearch/product_settings.json"),
      Charset.defaultCharset()
  );
  CreateIndexRequestBuilder createIndexRequestBuilder =
      esClient
          .admin()
          .indices()
          .prepareCreate(INDEX)
          .setSettings(settings);
  final String mapping = Resources.toString(
      getClass().getResource("/elasticsearch/product_mappings.json"),
      Charset.defaultCharset()
  );
  createIndexRequestBuilder = createIndexRequestBuilder.addMapping(TYPE, mapping);
  return createIndexRequestBuilder.get().isShardsAcked();
}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:28,代码来源:ProductDao.java

示例2: testMatchQueryWithStackedStems

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; //导入依赖的package包/类
public void testMatchQueryWithStackedStems() throws IOException {
    CreateIndexRequestBuilder builder = prepareCreate("test").setSettings(Settings.builder()
            .put(indexSettings())
            .put("index.analysis.analyzer.index.type", "custom")
            .put("index.analysis.analyzer.index.tokenizer", "standard")
            .put("index.analysis.analyzer.index.filter", "lowercase")
            .put("index.analysis.analyzer.search.type", "custom")
            .put("index.analysis.analyzer.search.tokenizer", "standard")
            .putArray("index.analysis.analyzer.search.filter", "lowercase", "keyword_repeat", "porter_stem", "unique_stem")
            .put("index.analysis.filter.unique_stem.type", "unique")
            .put("index.analysis.filter.unique_stem.only_on_same_position", true));
    assertAcked(builder.addMapping("test", "text", "type=text,analyzer=index,search_analyzer=search"));

    client().prepareIndex("test", "test", "1").setSource("text", "the fox runs across the street").get();
    refresh();
    SearchResponse searchResponse = client().prepareSearch("test").setQuery(matchQuery("text", "fox runs").operator(Operator.AND)).get();
    assertHitCount(searchResponse, 1);

    client().prepareIndex("test", "test", "2").setSource("text", "run fox run").get();
    refresh();
    searchResponse = client().prepareSearch("test").setQuery(matchQuery("text", "fox runs").operator(Operator.AND)).get();
    assertHitCount(searchResponse, 2);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:SearchQueryIT.java

示例3: testSimpleQueryStringAnalyzeWildcard

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; //导入依赖的package包/类
public void testSimpleQueryStringAnalyzeWildcard() throws ExecutionException, InterruptedException, IOException {
    String mapping = XContentFactory.jsonBuilder()
            .startObject()
            .startObject("type1")
            .startObject("properties")
            .startObject("location")
            .field("type", "text")
            .field("analyzer", "german")
            .endObject()
            .endObject()
            .endObject()
            .endObject().string();

    CreateIndexRequestBuilder mappingRequest = client().admin().indices().prepareCreate("test1")
        .addMapping("type1", mapping, XContentType.JSON);
    mappingRequest.execute().actionGet();
    indexRandom(true, client().prepareIndex("test1", "type1", "1").setSource("location", "Köln"));
    refresh();

    SearchResponse searchResponse = client().prepareSearch()
            .setQuery(simpleQueryStringQuery("Köln*").field("location")).get();
    assertNoFailures(searchResponse);
    assertHitCount(searchResponse, 1L);
    assertSearchHits(searchResponse, "1");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:SimpleQueryStringIT.java

示例4: testEmptySimpleQueryStringWithAnalysis

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; //导入依赖的package包/类
public void testEmptySimpleQueryStringWithAnalysis() throws Exception {
    // https://github.com/elastic/elasticsearch/issues/18202
    String mapping = XContentFactory.jsonBuilder()
            .startObject()
            .startObject("type1")
            .startObject("properties")
            .startObject("body")
            .field("type", "text")
            .field("analyzer", "stop")
            .endObject()
            .endObject()
            .endObject()
            .endObject().string();

    CreateIndexRequestBuilder mappingRequest = client().admin().indices()
            .prepareCreate("test1")
            .addMapping("type1", mapping, XContentType.JSON);
    mappingRequest.execute().actionGet();
    indexRandom(true, client().prepareIndex("test1", "type1", "1").setSource("body", "Some Text"));
    refresh();

    SearchResponse searchResponse = client().prepareSearch()
            .setQuery(simpleQueryStringQuery("the*").field("body")).get();
    assertNoFailures(searchResponse);
    assertHitCount(searchResponse, 0L);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:SimpleQueryStringIT.java

示例5: setUp

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; //导入依赖的package包/类
/**
 * Test setup.
 */
@Before
public void setUp() throws Exception {
    super.setUp();
    CreateIndexRequestBuilder builder = prepareCreate(INDEX).setSettings(
        Settings.builder()
            .put(indexSettings())
            .put("index.analysis.filter.syns.type", "synonym")
            .putArray("index.analysis.filter.syns.synonyms", "wtf, what the fudge", "foo, bar baz")
            .put("index.analysis.analyzer.lower_syns.type", "custom")
            .put("index.analysis.analyzer.lower_syns.tokenizer", "standard")
            .putArray("index.analysis.analyzer.lower_syns.filter", "lowercase", "syns")
            .put("index.analysis.filter.graphsyns.type", "synonym_graph")
            .putArray("index.analysis.filter.graphsyns.synonyms", "wtf, what the fudge", "foo, bar baz")
            .put("index.analysis.analyzer.lower_graphsyns.type", "custom")
            .put("index.analysis.analyzer.lower_graphsyns.tokenizer", "standard")
            .putArray("index.analysis.analyzer.lower_graphsyns.filter", "lowercase", "graphsyns")
    );

    assertAcked(builder.addMapping(INDEX, createMapping()));
    ensureGreen();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:MatchQueryIT.java

示例6: testCreateIndexWithoutSettings

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; //导入依赖的package包/类
@Test
public void testCreateIndexWithoutSettings() {
    // Test data
    final String indexName = "Index_Name";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final CreateIndexRequestBuilder createIndexRequestBuilder = createMock(CreateIndexRequestBuilder.class);
    final CreateIndexResponse createIndexResponse = createMock(CreateIndexResponse.class);
    // Reset
    resetAll();
    // Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareCreate(indexName)).andReturn(createIndexRequestBuilder);
    expect(createIndexRequestBuilder.get()).andReturn(createIndexResponse);
    // Replay
    replayAll();
    // Run test scenario
    final boolean result = elasticsearchClientWrapper.createIndex(indexName);
    // Verify
    verifyAll();
    assertEquals(createIndexResponse.isAcknowledged(), result);
}
 
开发者ID:Biacode,项目名称:escommons,代码行数:24,代码来源:ElasticsearchClientWrapperImplTest.java

示例7: testCreateIndex

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; //导入依赖的package包/类
@Test
public void testCreateIndex() {
    // Test data
    final String indexName = "Index_Name";
    final Map<String, Object> settings = Collections.singletonMap("settings_key", "settings_value");
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final CreateIndexRequestBuilder createIndexRequestBuilder = createMock(CreateIndexRequestBuilder.class);
    final CreateIndexResponse createIndexResponse = createMock(CreateIndexResponse.class);
    // Reset
    resetAll();
    // Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareCreate(indexName)).andReturn(createIndexRequestBuilder);
    expect(createIndexRequestBuilder.setSettings(settings)).andReturn(createIndexRequestBuilder);
    expect(createIndexRequestBuilder.get()).andReturn(createIndexResponse);
    // Replay
    replayAll();
    // Run test scenario
    final boolean result = elasticsearchClientWrapper.createIndex(indexName, settings);
    // Verify
    verifyAll();
    assertEquals(createIndexResponse.isAcknowledged(), result);
}
 
开发者ID:Biacode,项目名称:escommons,代码行数:26,代码来源:ElasticsearchClientWrapperImplTest.java

示例8: createIndex

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; //导入依赖的package包/类
@Override
protected void createIndex() throws JsonProcessingException {
    logger.info(String.format("Creating index [%s]", INDEX));

    CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(INDEX);
    org.elasticsearch.common.settings.Settings indexSettings = org.elasticsearch.common.settings.Settings.settingsBuilder()
            .put("number_of_shards", 3)
            .put("number_of_replicas", 1)
            //.put("analyzer", createDefaultAnalyzer())
            .build();
    createIndexRequestBuilder.setSettings(indexSettings);
    createIndexRequestBuilder.addMapping(recordDao.getType(), recordDao.createTypeMapping());
    createIndexRequestBuilder.addMapping(commentDao.getType(), commentDao.createTypeMapping());
    createIndexRequestBuilder.addMapping(MarketIndexDao.CATEGORY_TYPE, createCategoryTypeMapping());
    createIndexRequestBuilder.execute().actionGet();

    // Fill categories
    fillRecordCategories();
}
 
开发者ID:duniter-gchange,项目名称:gchange-pod,代码行数:20,代码来源:MarketIndexDaoImpl.java

示例9: createIndex

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; //导入依赖的package包/类
@Override
protected void createIndex() throws JsonProcessingException {
    logger.info(String.format("Creating index [%s]", INDEX));

    CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(INDEX);
    org.elasticsearch.common.settings.Settings indexSettings = org.elasticsearch.common.settings.Settings.settingsBuilder()
            .put("number_of_shards", 3)
            .put("number_of_replicas", 1)
            //.put("analyzer", createDefaultAnalyzer())
            .build();
    createIndexRequestBuilder.setSettings(indexSettings);
    createIndexRequestBuilder.addMapping(recordDao.getType(), recordDao.createTypeMapping());
    createIndexRequestBuilder.addMapping(commentDao.getType(), commentDao.createTypeMapping());
    createIndexRequestBuilder.addMapping(RegistryIndexDao.CATEGORY_TYPE, createCategoryTypeMapping());
    createIndexRequestBuilder.execute().actionGet();

    // Fill categories
    fillRecordCategories();
}
 
开发者ID:duniter-gchange,项目名称:gchange-pod,代码行数:20,代码来源:RegistryIndexDaoImpl.java

示例10: createIndexIfNotExists

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; //导入依赖的package包/类
public void createIndexIfNotExists(String index, String settingJson, Map<String, String> mappingJson) {
    String formattedIndex = formatIndex(index);
    IndicesAdminClient indicesClient = client.admin().indices();

    IndicesExistsResponse existsResponse = indicesClient.prepareExists(formattedIndex).get();
    if (existsResponse.isExists()) {
        return;
    }

    CreateIndexRequestBuilder builder = indicesClient.prepareCreate(formattedIndex)
            .setSettings(Settings.settingsBuilder().loadFromSource(settingJson));
    mappingJson.forEach((k, v) -> {
        builder.addMapping(k, v);
    });

    CreateIndexResponse indexResponse = builder.get();
    if (!indexResponse.isAcknowledged()) {
        throw new ElasticsearchException(String.format("index %s の作成に失敗しました", index));
    }
}
 
开发者ID:otsecbsol,项目名称:linkbinder,代码行数:21,代码来源:ElasticsearchClient.java

示例11: call

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; //导入依赖的package包/类
@Override
public Observable<Boolean> call(String index) {
    Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch();
    CreateIndexRequestBuilder request = elasticsearch.get().admin().indices().prepareCreate(index);
    for (Map.Entry<String, String> entry : mappings.entrySet()) {
        String type = entry.getKey();
        String mapping = entry.getValue();
        request = request.addMapping(type, mapping);
    }
    if (settings != null) {
        request.setSettings(settings);
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Request %s", Jsonify.toString(request)));
    }

    return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout())
            .map(Optional::get)
            .doOnNext(createIndexResponse -> {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(format("Response %s", Jsonify.toString(createIndexResponse)));
                }
            })
            .map(AcknowledgedResponse::isAcknowledged);
}
 
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:27,代码来源:IndexCreate.java

示例12: createNewIndex

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; //导入依赖的package包/类
@Override
public void createNewIndex(String indexName) {
    if (!indexExists(indexName)) {
        CreateIndexRequestBuilder indexRequestBuilder = indicesAdminClient().prepareCreate(indexName);

        // TODO: SYNONYMS need to be moved to core
        /*
         * if (SynonymsHelper.isSynonymsEnabled()) {
         * indexRequestBuilder.setSettings(SynonymsHelper.
         * createIndexSettings()); }
         */
        CreateIndexResponse response = indexRequestBuilder.execute().actionGet();

        log.info("Index: " + indexName + ", isAcknowledged: " + response.isAcknowledged());
    }
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:17,代码来源:DefaultElasticsearchIndexHelper.java

示例13: createMapping

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; //导入依赖的package包/类
protected boolean createMapping(MappingConfiguration mapping, String indexId) {
    IndicesAdminClient indices = getClient().admin().indices();

    Map<String, Object> schema = schemaGenerator.generate(mapping);
    log.trace("Built schema creation request:\n{}", Arrays.toString(schema.entrySet().toArray()));

    // create metadata mapping and schema mapping
    CreateIndexRequestBuilder request = indices.prepareCreate(indexId)
            .addMapping(MetadataDataMapping.METADATA_TYPE_NAME, getMetadataSchema())
            .addMapping(mapping.getType(), schema);
    if (mapping.hasIndexCreationRequest()) {
        request.setSettings(mapping.getIndexCreationRequest());
    }

    CreateIndexResponse response = request.get();
    log.debug("Created indices: {}, acknowledged: {}", response, response.isAcknowledged());

    Map<String, Object> mdRecord = createMetadataRecord(mapping.getVersion(), mapping.getName());
    IndexResponse mdResponse = getClient().prepareIndex(indexId, MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID).setSource(mdRecord).get();
    log.debug("Saved mapping metadata '{}': {}", mdResponse.isCreated(), Arrays.toString(mdRecord.entrySet().toArray()));

    return (mdResponse.isCreated() && response.isAcknowledged());
}
 
开发者ID:52North,项目名称:youngs,代码行数:24,代码来源:ElasticsearchSink.java

示例14: addSchema

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; //导入依赖的package包/类
private void addSchema(int iter) {
       String indexIter = "";
       if (iter > 0) {
           indexIter += iter;
       }

       String mappingJSON = "{\"" + indexType + "\":{\"_timestamp\":{\"enabled\":true,\"store\":true,\"index\":\"not_analyzed\"},\"_all\":{\"enabled\":false},\"properties\":{\"trackId\":{\"type\":\"string\"},\"timestamp\":{\"type\":\"date\"},\"speed\":{\"type\":\"float\",\"index\":\"no\"}}}}";

       CreateIndexRequestBuilder builder = client.admin().indices().prepareCreate(indexName + indexIter);
       builder.addMapping(indexType, mappingJSON);

//builder.setSettings("index.number_of_shards", 1);
       //builder.setSettings("index.number_of_replicas", 0);
       //builder.setSettings("refresh_interval", "120s");
       builder.setSettings("index.store.type", "memory");

       CreateIndexResponse createResponse = builder.execute().actionGet();
       if (!createResponse.isAcknowledged()) {
           System.err.println("Index was not created!");
       }
   }
 
开发者ID:Esri,项目名称:performance-test-harness-for-geoevent,代码行数:22,代码来源:ElasticSearchClient.java

示例15: createIndex

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; //导入依赖的package包/类
private void createIndex() {
        final XContentBuilder mappingBuilder;
        try {
            CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(esIndex);
            //tweak the mapping: use Nested objects
            mappingBuilder = jsonBuilder().startObject().startObject(esType)
                    //disable _all
                    .startObject("_all").field("enabled", "false").endObject()
                    .startObject("properties")
//                    .startObject("_childDocuments_").field("type", "nested").field("include_in_parent", "false").endObject()
                    .startObject("_childDocuments_").field("type", "nested").endObject()
                    .endObject()
                    .endObject().endObject();
            createIndexRequestBuilder.addMapping(esType, mappingBuilder);
            createIndexRequestBuilder.execute().actionGet();
        } catch (IOException e) {
            log.error("Creation of index failed: " + e.getLocalizedMessage());
        }
    }
 
开发者ID:jmlucjav,项目名称:esURP,代码行数:20,代码来源:ESProcessor.java


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