Search in sources :

Example 21 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project crate by crate.

the class DocIndexMetaDataTest method testNewArrayMapping.

@Test
public void testNewArrayMapping() throws Exception {
    XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("_meta").field("primary_keys", "id").endObject().startObject("properties").startObject("id").field("type", "integer").field("index", "not_analyzed").endObject().startObject("title").field("type", "string").field("index", "no").endObject().startObject("array_col").field("type", "array").startObject("inner").field("type", "ip").field("index", "not_analyzed").endObject().endObject().startObject("nested").field("type", "object").startObject("properties").startObject("inner_nested").field("type", "array").startObject("inner").field("type", "date").field("index", "not_analyzed").endObject().endObject().endObject().endObject().endObject().endObject();
    IndexMetaData indexMetaData = getIndexMetaData("test1", builder);
    DocIndexMetaData docIndexMetaData = newMeta(indexMetaData, "test1");
    assertThat(docIndexMetaData.references().get(ColumnIdent.fromPath("array_col")).valueType(), is((DataType) new ArrayType(DataTypes.IP)));
    assertThat(docIndexMetaData.references().get(ColumnIdent.fromPath("nested.inner_nested")).valueType(), is((DataType) new ArrayType(DataTypes.TIMESTAMP)));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 22 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project crate by crate.

the class DocIndexMetaDataTest method testExtractPrimaryKey.

@Test
public void testExtractPrimaryKey() throws Exception {
    XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject(Constants.DEFAULT_MAPPING_TYPE).startObject("_meta").field("primary_keys", "id").endObject().startObject("properties").startObject("id").field("type", "integer").field("index", "not_analyzed").endObject().startObject("title").field("type", "string").field("index", "no").endObject().startObject("datum").field("type", "date").endObject().startObject("content").field("type", "string").field("index", "analyzed").field("analyzer", "standard").endObject().endObject().endObject().endObject();
    IndexMetaData metaData = getIndexMetaData("test3", builder);
    DocIndexMetaData md = newMeta(metaData, "test3");
    assertThat(md.primaryKey().size(), is(1));
    assertThat(md.primaryKey(), contains(new ColumnIdent("id")));
    builder = XContentFactory.jsonBuilder().startObject().startObject(Constants.DEFAULT_MAPPING_TYPE).startObject("properties").startObject("content").field("type", "string").field("index", "not_analyzed").endObject().endObject().endObject().endObject();
    md = newMeta(getIndexMetaData("test4", builder), "test4");
    // _id is always the fallback primary key
    assertThat(md.primaryKey().size(), is(1));
    builder = XContentFactory.jsonBuilder().startObject().startObject(Constants.DEFAULT_MAPPING_TYPE).endObject().endObject();
    md = newMeta(getIndexMetaData("test5", builder), "test5");
    assertThat(md.primaryKey().size(), is(1));
}
Also used : XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 23 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project crate by crate.

the class DocIndexMetaDataTest method extractRoutingColumn.

@Test
public void extractRoutingColumn() throws Exception {
    XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject(Constants.DEFAULT_MAPPING_TYPE).startObject("_meta").field("primary_keys", "id").endObject().startObject("properties").startObject("id").field("type", "integer").field("index", "not_analyzed").endObject().startObject("title").field("type", "multi_field").field("path", "just_name").startObject("fields").startObject("title").field("type", "string").field("index", "not_analyzed").endObject().startObject("ft").field("type", "string").field("index", "analyzed").field("analyzer", "english").endObject().endObject().endObject().startObject("datum").field("type", "date").endObject().startObject("content").field("type", "multi_field").field("path", "just_name").startObject("fields").startObject("content").field("type", "string").field("index", "no").endObject().startObject("ft").field("type", "string").field("index", "analyzed").field("analyzer", "english").endObject().endObject().endObject().endObject().endObject().endObject();
    DocIndexMetaData md = newMeta(getIndexMetaData("test8", builder), "test8");
    assertThat(md.routingCol(), is(new ColumnIdent("id")));
    builder = XContentFactory.jsonBuilder().startObject().startObject(Constants.DEFAULT_MAPPING_TYPE).startObject("properties").startObject("content").field("type", "string").field("index", "not_analyzed").endObject().endObject().endObject().endObject();
    md = newMeta(getIndexMetaData("test9", builder), "test8");
    assertThat(md.routingCol(), is(new ColumnIdent("_id")));
    builder = XContentFactory.jsonBuilder().startObject().startObject(Constants.DEFAULT_MAPPING_TYPE).startObject("_meta").array("primary_keys", "id", "num").field("routing", "num").endObject().startObject("properties").startObject("id").field("type", "integer").field("index", "not_analyzed").endObject().startObject("num").field("type", "long").field("index", "not_analyzed").endObject().startObject("content").field("type", "string").field("index", "no").endObject().endObject().endObject().endObject();
    md = newMeta(getIndexMetaData("test10", builder), "test10");
    assertThat(md.routingCol(), is(new ColumnIdent("num")));
}
Also used : XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 24 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project crate by crate.

the class DocIndexMetaDataTest method testDocSysColumnReferences.

@Test
public void testDocSysColumnReferences() throws Exception {
    XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject(Constants.DEFAULT_MAPPING_TYPE).startObject("properties").startObject("content").field("type", "string").field("index", "not_analyzed").endObject().endObject().endObject().endObject();
    DocIndexMetaData metaData = newMeta(getIndexMetaData("test", builder), "test");
    Reference id = metaData.references().get(new ColumnIdent("_id"));
    assertNotNull(id);
    Reference version = metaData.references().get(new ColumnIdent("_version"));
    assertNotNull(version);
    Reference score = metaData.references().get(new ColumnIdent("_score"));
    assertNotNull(score);
}
Also used : XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 25 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project crate by crate.

the class DocIndexMetaDataTest method testSchemaWithGeneratedColumn.

@Test
public void testSchemaWithGeneratedColumn() throws Exception {
    XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("_meta").startObject("generated_columns").field("week", "date_trunc('week', ts)").endObject().endObject().startObject("properties").startObject("ts").field("type", "date").endObject().startObject("week").field("type", "long").endObject().endObject();
    IndexMetaData metaData = getIndexMetaData("test1", builder, Settings.EMPTY, null);
    DocIndexMetaData md = newMeta(metaData, "test1");
    assertThat(md.columns().size(), is(2));
    Reference week = md.references().get(new ColumnIdent("week"));
    assertThat(week, Matchers.notNullValue());
    assertThat(week, instanceOf(GeneratedReference.class));
    assertThat(((GeneratedReference) week).formattedGeneratedExpression(), is("date_trunc('week', ts)"));
    assertThat(((GeneratedReference) week).generatedExpression(), isFunction("date_trunc", isLiteral("week"), isReference("ts")));
    assertThat(((GeneratedReference) week).referencedReferences(), contains(isReference("ts")));
}
Also used : XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)618 IOException (java.io.IOException)126 XContentParser (org.elasticsearch.common.xcontent.XContentParser)122 Settings (org.elasticsearch.common.settings.Settings)60 ArrayList (java.util.ArrayList)59 SearchResponse (org.elasticsearch.action.search.SearchResponse)56 Matchers.containsString (org.hamcrest.Matchers.containsString)53 HashMap (java.util.HashMap)47 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)43 Map (java.util.Map)41 RestRequest (org.elasticsearch.rest.RestRequest)37 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)36 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)35 Test (org.junit.Test)34 RestController (org.elasticsearch.rest.RestController)33 NodeClient (org.elasticsearch.client.node.NodeClient)32 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)32 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)32 GeoPoint (org.elasticsearch.common.geo.GeoPoint)31 CrateUnitTest (io.crate.test.integration.CrateUnitTest)28