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


Java IndexRequestBuilder类代码示例

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


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

示例1: testRegex

import org.elasticsearch.action.index.IndexRequestBuilder; //导入依赖的package包/类
public void testRegex() throws Exception {
    final CompletionMappingBuilder mapping = new CompletionMappingBuilder();
    createIndexAndMapping(mapping);
    int numDocs = 10;
    List<IndexRequestBuilder> indexRequestBuilders = new ArrayList<>();
    for (int i = 1; i <= numDocs; i++) {
        indexRequestBuilders.add(client().prepareIndex(INDEX, TYPE, "" + i)
                .setSource(jsonBuilder()
                                .startObject()
                                .startObject(FIELD)
                                .field("input", "sugg" + i + "estion")
                                .field("weight", i)
                                .endObject()
                                .endObject()
                ));
    }
    indexRandom(true, indexRequestBuilders);
    CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).regex("sugg.*es");
    assertSuggestions("foo", prefix, "sugg10estion", "sugg9estion", "sugg8estion", "sugg7estion", "sugg6estion");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:CompletionSuggestSearchIT.java

示例2: testWithDate

import org.elasticsearch.action.index.IndexRequestBuilder; //导入依赖的package包/类
public void testWithDate() throws Exception {
    List<IndexRequestBuilder> reqs = new ArrayList<>();
    reqs.add(client().prepareIndex("test", "doc", "1").setSource("f1", "foo", "f_date", "2015/09/02"));
    reqs.add(client().prepareIndex("test", "doc", "2").setSource("f1", "bar", "f_date", "2015/09/01"));
    indexRandom(true, false, reqs);

    SearchResponse resp = client().prepareSearch("test").setQuery(queryStringQuery("foo bar")).get();
    assertHits(resp.getHits(), "1", "2");
    assertHitCount(resp, 2L);

    resp = client().prepareSearch("test").setQuery(queryStringQuery("\"2015/09/02\"")).get();
    assertHits(resp.getHits(), "1");
    assertHitCount(resp, 1L);

    resp = client().prepareSearch("test").setQuery(queryStringQuery("bar \"2015/09/02\"")).get();
    assertHits(resp.getHits(), "1", "2");
    assertHitCount(resp, 2L);

    resp = client().prepareSearch("test").setQuery(queryStringQuery("\"2015/09/02\" \"2015/09/01\"")).get();
    assertHits(resp.getHits(), "1", "2");
    assertHitCount(resp, 2L);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:QueryStringIT.java

示例3: testDeleteByQueryOnReadOnlyIndex

import org.elasticsearch.action.index.IndexRequestBuilder; //导入依赖的package包/类
public void testDeleteByQueryOnReadOnlyIndex() throws Exception {
    createIndex("test");

    final int docs = randomIntBetween(1, 50);
    List<IndexRequestBuilder> builders = new ArrayList<>();
    for (int i = 0; i < docs; i++) {
        builders.add(client().prepareIndex("test", "test", Integer.toString(i)).setSource("field", 1));
    }
    indexRandom(true, true, true, builders);

    try {
        enableIndexBlock("test", IndexMetaData.SETTING_READ_ONLY);
        assertThat(deleteByQuery().source("test").refresh(true).get(), matcher().deleted(0).failures(docs));
    } finally {
        disableIndexBlock("test", IndexMetaData.SETTING_READ_ONLY);
    }

    assertHitCount(client().prepareSearch("test").setSize(0).get(), docs);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:DeleteByQueryBasicTests.java

示例4: testBasicAllQuery

import org.elasticsearch.action.index.IndexRequestBuilder; //导入依赖的package包/类
public void testBasicAllQuery() throws Exception {
    List<IndexRequestBuilder> reqs = new ArrayList<>();
    reqs.add(client().prepareIndex("test", "doc", "1").setSource("f1", "foo bar baz"));
    reqs.add(client().prepareIndex("test", "doc", "2").setSource("f2", "Bar"));
    reqs.add(client().prepareIndex("test", "doc", "3").setSource("f3", "foo bar baz"));
    indexRandom(true, false, reqs);

    SearchResponse resp = client().prepareSearch("test").setQuery(queryStringQuery("foo")).get();
    assertHitCount(resp, 2L);
    assertHits(resp.getHits(), "1", "3");

    resp = client().prepareSearch("test").setQuery(queryStringQuery("bar")).get();
    assertHitCount(resp, 2L);
    assertHits(resp.getHits(), "1", "3");

    resp = client().prepareSearch("test").setQuery(queryStringQuery("Bar")).get();
    assertHitCount(resp, 3L);
    assertHits(resp.getHits(), "1", "2", "3");

    resp = client().prepareSearch("test").setQuery(queryStringQuery("foa")).get();
    assertHitCount(resp, 1L);
    assertHits(resp.getHits(), "3");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:QueryStringIT.java

示例5: testNoopRequestBreaker

import org.elasticsearch.action.index.IndexRequestBuilder; //导入依赖的package包/类
public void testNoopRequestBreaker() throws Exception {
    assertAcked(prepareCreate("cb-test", 1, Settings.builder().put(SETTING_NUMBER_OF_REPLICAS, between(0, 1))));
    Client client = client();

    // index some different terms so we have some field data for loading
    int docCount = scaledRandomIntBetween(300, 1000);
    List<IndexRequestBuilder> reqs = new ArrayList<>();
    for (long id = 0; id < docCount; id++) {
        reqs.add(client.prepareIndex("cb-test", "type", Long.toString(id)).setSource("test", id));
    }
    indexRandom(true, reqs);

    // A cardinality aggregation uses BigArrays and thus the REQUEST breaker
    client.prepareSearch("cb-test").setQuery(matchAllQuery()).addAggregation(cardinality("card").field("test")).get();
    // no exception because the breaker is a noop
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:CircuitBreakerNoopIT.java

示例6: createAndPopulateIndex

import org.elasticsearch.action.index.IndexRequestBuilder; //导入依赖的package包/类
private IndicesStatsResponse createAndPopulateIndex(String name, int nodeCount, int shardCount, int replicaCount)
        throws ExecutionException, InterruptedException {

    logger.info("--> creating test index: {}", name);
    assertAcked(prepareCreate(name, nodeCount, Settings.builder().put("number_of_shards", shardCount)
            .put("number_of_replicas", replicaCount).put(Store.INDEX_STORE_STATS_REFRESH_INTERVAL_SETTING.getKey(), 0)));
    ensureGreen();

    logger.info("--> indexing sample data");
    final int numDocs = between(MIN_DOC_COUNT, MAX_DOC_COUNT);
    final IndexRequestBuilder[] docs = new IndexRequestBuilder[numDocs];

    for (int i = 0; i < numDocs; i++) {
        docs[i] = client().prepareIndex(name, INDEX_TYPE).
                setSource("foo-int", randomInt(),
                        "foo-string", randomAsciiOfLength(32),
                        "foo-float", randomFloat());
    }

    indexRandom(true, docs);
    flush();
    assertThat(client().prepareSearch(name).setSize(0).get().getHits().getTotalHits(), equalTo((long) numDocs));
    return client().admin().indices().prepareStats(name).execute().actionGet();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:IndexRecoveryIT.java

示例7: testSimpleMoreLikeThisIds

import org.elasticsearch.action.index.IndexRequestBuilder; //导入依赖的package包/类
public void testSimpleMoreLikeThisIds() throws Exception {
    logger.info("Creating index test");
    assertAcked(prepareCreate("test").addMapping("type1",
            jsonBuilder().startObject().startObject("type1").startObject("properties")
                    .startObject("text").field("type", "text").endObject()
                    .endObject().endObject().endObject()));

    logger.info("Running Cluster Health");
    assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));

    logger.info("Indexing...");
    List<IndexRequestBuilder> builders = new ArrayList<>();
    builders.add(client().prepareIndex("test", "type1").setSource("text", "lucene").setId("1"));
    builders.add(client().prepareIndex("test", "type1").setSource("text", "lucene release").setId("2"));
    builders.add(client().prepareIndex("test", "type1").setSource("text", "apache lucene").setId("3"));
    indexRandom(true, builders);

    logger.info("Running MoreLikeThis");
    MoreLikeThisQueryBuilder queryBuilder = QueryBuilders.moreLikeThisQuery(new String[] {"text"}, null, ids("1")).include(true).minTermFreq(1).minDocFreq(1);
    SearchResponse mltResponse = client().prepareSearch().setTypes("type1").setQuery(queryBuilder).execute().actionGet();
    assertHitCount(mltResponse, 3L);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:MoreLikeThisIT.java

示例8: indexRandomNumbers

import org.elasticsearch.action.index.IndexRequestBuilder; //导入依赖的package包/类
private int indexRandomNumbers(String analyzer, int shards, boolean dummyDocs) throws Exception {
    Builder builder = Settings.builder().put(indexSettings());

    if (shards > 0) {
        builder.put(SETTING_NUMBER_OF_SHARDS, shards);
    }

    assertAcked(prepareCreate("test")
            .addMapping(
                    "type1",
                    jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field1")
                            .field("analyzer", analyzer).field("type", "text").endObject().endObject().endObject().endObject())
            .setSettings(builder));
    int numDocs = randomIntBetween(100, 150);
    IndexRequestBuilder[] docs = new IndexRequestBuilder[numDocs];
    for (int i = 0; i < numDocs; i++) {
        docs[i] = client().prepareIndex("test", "type1", String.valueOf(i)).setSource("field1", English.intToEnglish(i));
    }

    indexRandom(true, dummyDocs, docs);
    ensureGreen();
    return numDocs;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:QueryRescorerIT.java

示例9: testSetSource

import org.elasticsearch.action.index.IndexRequestBuilder; //导入依赖的package包/类
public void testSetSource() throws InterruptedException, ExecutionException {
    createIndex("test");
    Map<String, Object> map = new HashMap<>();
    map.put("test_field", "foobar");
    IndexRequestBuilder[] builders = new IndexRequestBuilder[] {
            client().prepareIndex("test", "test").setSource((Object)"test_field", (Object)"foobar"),
            client().prepareIndex("test", "test").setSource("{\"test_field\" : \"foobar\"}", XContentType.JSON),
            client().prepareIndex("test", "test").setSource(new BytesArray("{\"test_field\" : \"foobar\"}"), XContentType.JSON),
            client().prepareIndex("test", "test").setSource(new BytesArray("{\"test_field\" : \"foobar\"}"), XContentType.JSON),
            client().prepareIndex("test", "test")
                .setSource(BytesReference.toBytes(new BytesArray("{\"test_field\" : \"foobar\"}")), XContentType.JSON),
            client().prepareIndex("test", "test").setSource(map)
    };
    indexRandom(true, builders);
    SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.termQuery("test_field", "foobar")).get();
    ElasticsearchAssertions.assertHitCount(searchResponse, builders.length);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:IndexRequestBuilderIT.java

示例10: addEvent

import org.elasticsearch.action.index.IndexRequestBuilder; //导入依赖的package包/类
@Override
public void addEvent(Event event, IndexNameBuilder indexNameBuilder,
    String indexType, long ttlMs) throws Exception {
  if (bulkRequestBuilder == null) {
    bulkRequestBuilder = client.prepareBulk();
  }

  IndexRequestBuilder indexRequestBuilder = null;
  if (indexRequestBuilderFactory == null) {
    indexRequestBuilder = client
        .prepareIndex(indexNameBuilder.getIndexName(event), indexType)
        .setSource(serializer.getContentBuilder(event).bytes());
  } else {
    indexRequestBuilder = indexRequestBuilderFactory.createIndexRequest(
        client, indexNameBuilder.getIndexPrefix(event), indexType, event);
  }

  if (ttlMs > 0) {
    indexRequestBuilder.setTTL(ttlMs);
  }
  bulkRequestBuilder.add(indexRequestBuilder);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:23,代码来源:ElasticSearchTransportClient.java

示例11: save

import org.elasticsearch.action.index.IndexRequestBuilder; //导入依赖的package包/类
public void save(JSONObject jsonObject) throws LogConsumerException {
    if (jsonObject == null)
        return;
    LogcenterConfig config = LogConfigCache.getLogConfigCache(jsonObject);
    String indexName = buildIndexName(config);
    boolean isExists = indexIsExists(indexName);
    if (!isExists)
        crateIndex(config);
    String id = jsonObject.getString(Constants.PRIMARY_KEY);
    jsonObject.remove(Constants.PRIMARY_KEY);
    String source = "";
    switch (config.getContentType()) {
        case "0"://字符串
            source = jsonObject.toJSONString();
            break;
        case "1"://json
            source = ((JSONObject) jsonObject.get("msg")).toJSONString();
            break;
    }
    IndexRequestBuilder builder = ElasticsearchClient.getClient()
            .prepareIndex(indexName, config.getTypeName())
            .setId(String.valueOf(id))
            .setSource(source);

    ElasticsearchBulkTools.addUpdateBuilderToBulk(builder);
}
 
开发者ID:geeker-lait,项目名称:tasfe-framework,代码行数:27,代码来源:ElasticsearchSpi.java

示例12: indexRandomFrequencies01

import org.elasticsearch.action.index.IndexRequestBuilder; //导入依赖的package包/类
private void indexRandomFrequencies01(String type) throws ExecutionException, InterruptedException {
    String textMappings = "type=" + type;
    if (type.equals("text")) {
        textMappings += ",fielddata=true";
    }
    assertAcked(prepareCreate(INDEX_NAME).addMapping(DOC_TYPE, TEXT_FIELD, textMappings, CLASS_FIELD, "type=keyword"));
    String[] gb = {"0", "1"};
    List<IndexRequestBuilder> indexRequestBuilderList = new ArrayList<>();
    for (int i = 0; i < randomInt(20); i++) {
        int randNum = randomInt(2);
        String[] text = new String[1];
        if (randNum == 2) {
            text = gb;
        } else {
            text[0] = gb[randNum];
        }
        indexRequestBuilderList.add(client().prepareIndex(INDEX_NAME, DOC_TYPE)
                .setSource(TEXT_FIELD, text, CLASS_FIELD, randomBoolean() ? "one" : "zero"));
    }
    indexRandom(true, indexRequestBuilderList);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:SignificantTermsSignificanceScoreIT.java

示例13: createIndex

import org.elasticsearch.action.index.IndexRequestBuilder; //导入依赖的package包/类
private int createIndex(boolean singleShard) throws Exception {
    Settings.Builder settings = Settings.builder();
    if (singleShard) {
        settings.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1);
    }
    // no replicas, as they might be ordered differently
    settings.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0);

    assertAcked(prepareCreate("test").setSettings(settings.build()).get());
    final int numDocs = randomIntBetween(10, 200);

    IndexRequestBuilder[] builders = new IndexRequestBuilder[numDocs];
    for (int i = 0; i < numDocs; ++i) {
        builders[i] = client().prepareIndex("test", "type", Integer.toString(i)).setSource("foo", random().nextBoolean());
    }
    indexRandom(true, builders);
    return numDocs;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:DuelScrollIT.java

示例14: canIndexDocument

import org.elasticsearch.action.index.IndexRequestBuilder; //导入依赖的package包/类
private void canIndexDocument(String index) {
    try {
        IndexRequestBuilder builder = client().prepareIndex(index, "zzz");
        builder.setSource("foo", "bar");
        IndexResponse r = builder.execute().actionGet();
        assertThat(r, notNullValue());
    } catch (ClusterBlockException e) {
        fail();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:SimpleBlocksIT.java

示例15: setupSuiteScopeCluster

import org.elasticsearch.action.index.IndexRequestBuilder; //导入依赖的package包/类
@Override
public void setupSuiteScopeCluster() throws Exception {
    createIndex("idx", "idx_unmapped");
    // TODO: would be nice to have more random data here
    assertAcked(prepareCreate("empty_bucket_idx").addMapping("type", "value", "type=integer"));
    List<IndexRequestBuilder> builders = new ArrayList<>();
    for (int i = 0; i < 2; i++) {
        builders.add(client().prepareIndex("empty_bucket_idx", "type", "" + i).setSource(jsonBuilder()
                .startObject()
                .field("value", i * 2)
                .endObject()));
    }
    builders.addAll(Arrays.asList(
            indexDoc(1, 2, 1),  // date: Jan 2, dates: Jan 2, Feb 3
            indexDoc(2, 2, 2),  // date: Feb 2, dates: Feb 2, Mar 3
            indexDoc(2, 15, 3), // date: Feb 15, dates: Feb 15, Mar 16
            indexDoc(3, 2, 4),  // date: Mar 2, dates: Mar 2, Apr 3
            indexDoc(3, 15, 5), // date: Mar 15, dates: Mar 15, Apr 16
            indexDoc(3, 23, 6))); // date: Mar 23, dates: Mar 23, Apr 24
    indexRandom(true, builders);
    ensureSearchable();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:DateHistogramIT.java


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