本文整理匯總了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");
}
示例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);
}
示例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);
}
示例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");
}
示例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
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
}
示例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();
}