Search in sources :

Example 11 with IndicesExistsRequest

use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project crate by crate.

the class DDLIntegrationTest method testCreateTableWithCompositeIndex.

@Test
public void testCreateTableWithCompositeIndex() throws Exception {
    execute("create table novels (title string, description string, " + "index title_desc_fulltext using fulltext(title, description) " + "with(analyzer='english')) with (number_of_replicas = 0)");
    ensureYellow();
    assertTrue(client().admin().indices().exists(new IndicesExistsRequest("novels")).actionGet().isExists());
    String title = "So Long, and Thanks for All the Fish";
    String description = "Many were increasingly of the opinion that they'd all made a big " + "mistake in coming down from the trees in the first place. And some said that " + "even the trees had been a bad move, and that no one should ever have left " + "the oceans.";
    execute("insert into novels (title, description) values(?, ?)", new Object[] { title, description });
    refresh();
    // match token existing at field `title`
    execute("select title, description from novels where match(title_desc_fulltext, 'fish')");
    assertEquals(1L, response.rowCount());
    assertEquals(title, response.rows()[0][0]);
    assertEquals(description, response.rows()[0][1]);
    // match token existing at field `description`
    execute("select title, description from novels where match(title_desc_fulltext, 'oceans')");
    assertEquals(1L, response.rowCount());
    assertEquals(title, response.rows()[0][0]);
    assertEquals(description, response.rows()[0][1]);
    // filtering on the actual values does still work
    execute("select title from novels where title = ?", new Object[] { title });
    assertEquals(1L, response.rowCount());
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest) Test(org.junit.Test)

Example 12 with IndicesExistsRequest

use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project crate by crate.

the class DDLIntegrationTest method testCreateTableWithIndexOff.

@Test
public void testCreateTableWithIndexOff() throws Exception {
    execute("create table quotes (id int, quote string index off) with (number_of_replicas = 0)");
    ensureYellow();
    assertTrue(client().admin().indices().exists(new IndicesExistsRequest("quotes")).actionGet().isExists());
    String quote = "Would it save you a lot of time if I just gave up and went mad now?";
    execute("insert into quotes (id, quote) values (?, ?)", new Object[] { 1, quote });
    refresh();
    execute("select quote from quotes where quote = ?", new Object[] { quote });
    assertEquals(0, response.rowCount());
    execute("select quote from quotes where id = 1");
    assertEquals(1L, response.rowCount());
    assertEquals(quote, response.rows()[0][0]);
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest) Test(org.junit.Test)

Example 13 with IndicesExistsRequest

use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project crate by crate.

the class DDLIntegrationTest method testCreateTableWithInlineDefaultIndex.

@Test
public void testCreateTableWithInlineDefaultIndex() throws Exception {
    execute("create table quotes (quote string index using plain) with (number_of_replicas = 0)");
    ensureYellow();
    assertTrue(client().admin().indices().exists(new IndicesExistsRequest("quotes")).actionGet().isExists());
    String quote = "Would it save you a lot of time if I just gave up and went mad now?";
    execute("insert into quotes values (?)", new Object[] { quote });
    refresh();
    // matching does not work on plain indexes
    execute("select quote from quotes where match(quote, 'time')");
    assertEquals(0, response.rowCount());
    // filtering on the actual value does work
    execute("select quote from quotes where quote = ?", new Object[] { quote });
    assertEquals(1L, response.rowCount());
    assertEquals(quote, response.rows()[0][0]);
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest) Test(org.junit.Test)

Example 14 with IndicesExistsRequest

use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project crate by crate.

the class DDLIntegrationTest method testCreateTableWithReplicasAndShards.

@Test
public void testCreateTableWithReplicasAndShards() throws Exception {
    execute("create table test (col1 integer primary key, col2 string)" + "clustered by (col1) into 10 shards with (number_of_replicas=2)");
    assertTrue(client().admin().indices().exists(new IndicesExistsRequest("test")).actionGet().isExists());
    String expectedMapping = "{\"default\":{" + "\"dynamic\":\"true\"," + "\"_meta\":{" + "\"primary_keys\":[\"col1\"]," + "\"routing\":\"col1\"}," + "\"_all\":{\"enabled\":false}," + "\"properties\":{" + "\"col1\":{\"type\":\"integer\"}," + "\"col2\":{\"type\":\"string\",\"index\":\"not_analyzed\"}" + "}}}";
    String expectedSettings = "{\"test\":{" + "\"settings\":{" + "\"index.number_of_replicas\":\"2\"," + "\"index.number_of_shards\":\"10\"," + "\"index.version.created\":\"" + Version.CURRENT.esVersion.id + "\"" + "}}}";
    JSONAssert.assertEquals(expectedMapping, getIndexMapping("test"), JSONCompareMode.LENIENT);
    JSONAssert.assertEquals(expectedSettings, getIndexSettings("test"), JSONCompareMode.LENIENT);
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest) Test(org.junit.Test)

Example 15 with IndicesExistsRequest

use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project elasticsearch by elastic.

the class IndicesExistsIT method testIndicesExists.

// Indices exists never throws IndexMissingException, the indices options control its behaviour (return true or false)
public void testIndicesExists() throws Exception {
    assertFalse(client().admin().indices().prepareExists("foo").get().isExists());
    assertFalse(client().admin().indices().prepareExists("foo*").get().isExists());
    assertFalse(client().admin().indices().prepareExists("_all").get().isExists());
    createIndex("foo", "foobar", "bar", "barbaz");
    IndicesExistsRequestBuilder indicesExistsRequestBuilder = client().admin().indices().prepareExists("foo*").setExpandWildcardsOpen(false);
    IndicesExistsRequest request = indicesExistsRequestBuilder.request();
    //check that ignore unavailable and allow no indices are set to false. That is their only valid value as it can't be overridden
    assertFalse(request.indicesOptions().ignoreUnavailable());
    assertFalse(request.indicesOptions().allowNoIndices());
    assertThat(indicesExistsRequestBuilder.get().isExists(), equalTo(false));
    assertAcked(client().admin().indices().prepareClose("foobar").get());
    assertThat(client().admin().indices().prepareExists("foo*").get().isExists(), equalTo(true));
    assertThat(client().admin().indices().prepareExists("foo*").setExpandWildcardsOpen(false).setExpandWildcardsClosed(false).get().isExists(), equalTo(false));
    assertThat(client().admin().indices().prepareExists("foobar").get().isExists(), equalTo(true));
    assertThat(client().admin().indices().prepareExists("foob*").setExpandWildcardsClosed(false).get().isExists(), equalTo(false));
    assertThat(client().admin().indices().prepareExists("bar*").get().isExists(), equalTo(true));
    assertThat(client().admin().indices().prepareExists("bar").get().isExists(), equalTo(true));
    assertThat(client().admin().indices().prepareExists("_all").get().isExists(), equalTo(true));
}
Also used : IndicesExistsRequestBuilder(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)

Aggregations

IndicesExistsRequest (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)17 Test (org.junit.Test)13 Matchers.containsString (org.hamcrest.Matchers.containsString)9 IndicesExistsResponse (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse)4 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)2 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)2 PartitionName (io.crate.metadata.PartitionName)2 BytesRef (org.apache.lucene.util.BytesRef)2 FailedException (backtype.storm.topology.FailedException)1 TitanException (com.thinkaurelius.titan.core.TitanException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ElasticSearchException (org.elasticsearch.ElasticSearchException)1 Alias (org.elasticsearch.action.admin.indices.alias.Alias)1 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)1 IndicesExistsRequestBuilder (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder)1 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)1 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)1 IndicesAdminClient (org.elasticsearch.client.IndicesAdminClient)1 ImmutableSettings (org.elasticsearch.common.settings.ImmutableSettings)1