Search in sources :

Example 11 with CreateIndexRequestBuilder

use of org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder in project sonarqube by SonarSource.

the class ProxyCreateIndexRequestBuilderTest method create_index.

@Test
public void create_index() {
    CreateIndexRequestBuilder requestBuilder = esTester.client().prepareCreate(generateNewIndexName());
    requestBuilder.get();
}
Also used : CreateIndexRequestBuilder(org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder) Test(org.junit.Test)

Example 12 with CreateIndexRequestBuilder

use of org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder in project elasticsearch-opennlp-plugin by spinscale.

the class OpenNlpPluginIntegrationTest method startNode.

@Before
public void startNode() throws Exception {
    node = createNode(clusterName).start();
    CreateIndexResponse createIndexResponse = new CreateIndexRequestBuilder(node.client().admin().indices()).setIndex(index).execute().actionGet();
    assertThat(createIndexResponse.isAcknowledged(), is(true));
}
Also used : CreateIndexRequestBuilder(org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) Before(org.junit.Before)

Example 13 with CreateIndexRequestBuilder

use of org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder in project elasticsearch by elastic.

the class MoreLikeThisIT method testSimpleMoreLikeThisIdsMultipleTypes.

public void testSimpleMoreLikeThisIdsMultipleTypes() throws Exception {
    logger.info("Creating index test");
    int numOfTypes = randomIntBetween(2, 10);
    CreateIndexRequestBuilder createRequestBuilder = prepareCreate("test");
    for (int i = 0; i < numOfTypes; i++) {
        createRequestBuilder.addMapping("type" + i, jsonBuilder().startObject().startObject("type" + i).startObject("properties").startObject("text").field("type", "text").endObject().endObject().endObject().endObject());
    }
    assertAcked(createRequestBuilder);
    logger.info("Running Cluster Health");
    assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));
    logger.info("Indexing...");
    List<IndexRequestBuilder> builders = new ArrayList<>(numOfTypes);
    for (int i = 0; i < numOfTypes; i++) {
        builders.add(client().prepareIndex("test", "type" + i).setSource("text", "lucene" + " " + i).setId(String.valueOf(i)));
    }
    indexRandom(true, builders);
    logger.info("Running MoreLikeThis");
    MoreLikeThisQueryBuilder queryBuilder = QueryBuilders.moreLikeThisQuery(new String[] { "text" }, null, new Item[] { new Item("test", "type0", "0") }).include(true).minTermFreq(1).minDocFreq(1);
    String[] types = new String[numOfTypes];
    for (int i = 0; i < numOfTypes; i++) {
        types[i] = "type" + i;
    }
    SearchResponse mltResponse = client().prepareSearch().setTypes(types).setQuery(queryBuilder).execute().actionGet();
    assertHitCount(mltResponse, numOfTypes);
}
Also used : CreateIndexRequestBuilder(org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) Item(org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item) CreateIndexRequestBuilder(org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder) ArrayList(java.util.ArrayList) MoreLikeThisQueryBuilder(org.elasticsearch.index.query.MoreLikeThisQueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 14 with CreateIndexRequestBuilder

use of org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder in project elasticsearch by elastic.

the class MultiMatchQueryIT method init.

@Before
public void init() throws Exception {
    CreateIndexRequestBuilder builder = prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0).put("index.analysis.analyzer.perfect_match.type", "custom").put("index.analysis.analyzer.perfect_match.tokenizer", "keyword").put("index.analysis.analyzer.perfect_match.filter", "lowercase").put("index.analysis.analyzer.category.type", "custom").put("index.analysis.analyzer.category.tokenizer", "whitespace").put("index.analysis.analyzer.category.filter", "lowercase"));
    assertAcked(builder.addMapping("test", createMapping()));
    ensureGreen();
    int numDocs = scaledRandomIntBetween(50, 100);
    List<IndexRequestBuilder> builders = new ArrayList<>();
    builders.add(client().prepareIndex("test", "test", "theone").setSource("full_name", "Captain America", "first_name", "Captain", "last_name", "America", "category", "marvel hero", "skill", 15, "int-field", 25));
    builders.add(client().prepareIndex("test", "test", "theother").setSource("full_name", "marvel hero", "first_name", "marvel", "last_name", "hero", "category", "bogus", "skill", 5));
    builders.add(client().prepareIndex("test", "test", "ultimate1").setSource("full_name", "Alpha the Ultimate Mutant", "first_name", "Alpha the", "last_name", "Ultimate Mutant", "category", "marvel hero", "skill", 1));
    builders.add(client().prepareIndex("test", "test", "ultimate2").setSource("full_name", "Man the Ultimate Ninja", "first_name", "Man the Ultimate", "last_name", "Ninja", "category", "marvel hero", "skill", 3));
    builders.add(client().prepareIndex("test", "test", "anotherhero").setSource("full_name", "ultimate", "first_name", "wolferine", "last_name", "", "category", "marvel hero", "skill", 1));
    builders.add(client().prepareIndex("test", "test", "nowHero").setSource("full_name", "now sort of", "first_name", "now", "last_name", "", "category", "marvel hero", "skill", 1));
    List<String> firstNames = new ArrayList<>();
    fill(firstNames, "Captain", between(15, 25));
    fill(firstNames, "Ultimate", between(5, 10));
    fillRandom(firstNames, between(3, 7));
    List<String> lastNames = new ArrayList<>();
    fill(lastNames, "Captain", between(3, 7));
    fillRandom(lastNames, between(30, 40));
    for (int i = 0; i < numDocs; i++) {
        String first = RandomPicks.randomFrom(random(), firstNames);
        String last = randomPickExcept(lastNames, first);
        builders.add(client().prepareIndex("test", "test", "" + i).setSource("full_name", first + " " + last, "first_name", first, "last_name", last, "category", randomBoolean() ? "marvel hero" : "bogus", "skill", between(1, 3)));
    }
    indexRandom(true, false, builders);
}
Also used : CreateIndexRequestBuilder(org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) CreateIndexRequestBuilder(org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Example 15 with CreateIndexRequestBuilder

use of org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder in project elasticsearch by elastic.

the class QueryStringIT method setupIndexWithGraph.

private void setupIndexWithGraph(String index) throws Exception {
    CreateIndexRequestBuilder builder = prepareCreate(index).setSettings(Settings.builder().put(indexSettings()).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"));
    XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject(index).startObject("properties").startObject("field").field("type", "text").endObject().endObject().endObject().endObject();
    assertAcked(builder.addMapping(index, mapping));
    ensureGreen();
    List<IndexRequestBuilder> builders = new ArrayList<>();
    builders.add(client().prepareIndex(index, index, "1").setSource("field", "say wtf happened foo"));
    builders.add(client().prepareIndex(index, index, "2").setSource("field", "bar baz what the fudge man"));
    builders.add(client().prepareIndex(index, index, "3").setSource("field", "wtf"));
    builders.add(client().prepareIndex(index, index, "4").setSource("field", "what is the name for fudge"));
    builders.add(client().prepareIndex(index, index, "5").setSource("field", "bar two three"));
    builders.add(client().prepareIndex(index, index, "6").setSource("field", "bar baz two three"));
    indexRandom(true, false, builders);
}
Also used : CreateIndexRequestBuilder(org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) CreateIndexRequestBuilder(org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder) ArrayList(java.util.ArrayList) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Aggregations

CreateIndexRequestBuilder (org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder)30 SearchResponse (org.elasticsearch.action.search.SearchResponse)11 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)11 ArrayList (java.util.ArrayList)8 PhraseSuggestionBuilder (org.elasticsearch.search.suggest.phrase.PhraseSuggestionBuilder)7 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)6 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Before (org.junit.Before)3 SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)2 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)2 DirectCandidateGeneratorBuilder (org.elasticsearch.search.suggest.phrase.DirectCandidateGeneratorBuilder)2 StupidBackoff (org.elasticsearch.search.suggest.phrase.StupidBackoff)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 Alias (org.elasticsearch.action.admin.indices.alias.Alias)1 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)1 BytesReference (org.elasticsearch.common.bytes.BytesReference)1