Search in sources :

Example 1 with GetMappingsResponse

use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse in project elasticsearch by elastic.

the class SizeMappingIT method assertSizeMappingEnabled.

private void assertSizeMappingEnabled(String index, String type, boolean enabled) throws IOException {
    String errMsg = String.format(Locale.ROOT, "Expected size field mapping to be " + (enabled ? "enabled" : "disabled") + " for %s/%s", index, type);
    GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings(index).addTypes(type).get();
    Map<String, Object> mappingSource = getMappingsResponse.getMappings().get(index).get(type).getSourceAsMap();
    assertThat(errMsg, mappingSource, hasKey("_size"));
    String sizeAsString = mappingSource.get("_size").toString();
    assertThat(sizeAsString, is(notNullValue()));
    assertThat(errMsg, sizeAsString, is("{enabled=" + (enabled) + "}"));
}
Also used : GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)

Example 2 with GetMappingsResponse

use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse in project elasticsearch by elastic.

the class MultiFieldsIntegrationIT method testCompletionMultiField.

public void testCompletionMultiField() throws Exception {
    assertAcked(client().admin().indices().prepareCreate("my-index").addMapping("my-type", createMappingSource("completion")));
    GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get();
    MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type");
    assertThat(mappingMetaData, not(nullValue()));
    Map<String, Object> mappingSource = mappingMetaData.sourceAsMap();
    Map aField = ((Map) XContentMapValues.extractValue("properties.a", mappingSource));
    assertThat(aField.size(), equalTo(6));
    assertThat(aField.get("type").toString(), equalTo("completion"));
    assertThat(aField.get("fields"), notNullValue());
    Map bField = ((Map) XContentMapValues.extractValue("properties.a.fields.b", mappingSource));
    assertThat(bField.size(), equalTo(1));
    assertThat(bField.get("type").toString(), equalTo("keyword"));
    client().prepareIndex("my-index", "my-type", "1").setSource("a", "complete me").setRefreshPolicy(IMMEDIATE).get();
    SearchResponse countResponse = client().prepareSearch("my-index").setSize(0).setQuery(matchQuery("a.b", "complete me")).get();
    assertThat(countResponse.getHits().getTotalHits(), equalTo(1L));
}
Also used : MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) Map(java.util.Map) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 3 with GetMappingsResponse

use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse in project elasticsearch by elastic.

the class MultiFieldsIntegrationIT method testTokenCountMultiField.

public void testTokenCountMultiField() throws Exception {
    assertAcked(client().admin().indices().prepareCreate("my-index").addMapping("my-type", XContentFactory.jsonBuilder().startObject().startObject("my-type").startObject("properties").startObject("a").field("type", "token_count").field("analyzer", "simple").startObject("fields").startObject("b").field("type", "keyword").endObject().endObject().endObject().endObject().endObject().endObject()));
    GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get();
    MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type");
    assertThat(mappingMetaData, not(nullValue()));
    Map<String, Object> mappingSource = mappingMetaData.sourceAsMap();
    Map aField = ((Map) XContentMapValues.extractValue("properties.a", mappingSource));
    assertThat(aField.size(), equalTo(3));
    assertThat(aField.get("type").toString(), equalTo("token_count"));
    assertThat(aField.get("fields"), notNullValue());
    Map bField = ((Map) XContentMapValues.extractValue("properties.a.fields.b", mappingSource));
    assertThat(bField.size(), equalTo(1));
    assertThat(bField.get("type").toString(), equalTo("keyword"));
    client().prepareIndex("my-index", "my-type", "1").setSource("a", "my tokens").setRefreshPolicy(IMMEDIATE).get();
    SearchResponse countResponse = client().prepareSearch("my-index").setSize(0).setQuery(matchQuery("a.b", "my tokens")).get();
    assertThat(countResponse.getHits().getTotalHits(), equalTo(1L));
}
Also used : MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) Map(java.util.Map) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 4 with GetMappingsResponse

use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse in project elasticsearch by elastic.

the class DynamicMappingIT method testConcurrentDynamicUpdates.

public void testConcurrentDynamicUpdates() throws Throwable {
    createIndex("index");
    final Thread[] indexThreads = new Thread[32];
    final CountDownLatch startLatch = new CountDownLatch(1);
    final AtomicReference<Throwable> error = new AtomicReference<>();
    for (int i = 0; i < indexThreads.length; ++i) {
        final String id = Integer.toString(i);
        indexThreads[i] = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    startLatch.await();
                    assertEquals(DocWriteResponse.Result.CREATED, client().prepareIndex("index", "type", id).setSource("field" + id, "bar").get().getResult());
                } catch (Exception e) {
                    error.compareAndSet(null, e);
                }
            }
        });
        indexThreads[i].start();
    }
    startLatch.countDown();
    for (Thread thread : indexThreads) {
        thread.join();
    }
    if (error.get() != null) {
        throw error.get();
    }
    Thread.sleep(2000);
    GetMappingsResponse mappings = client().admin().indices().prepareGetMappings("index").setTypes("type").get();
    for (int i = 0; i < indexThreads.length; ++i) {
        assertMappingsHaveField(mappings, "index", "type", "field" + i);
    }
    for (int i = 0; i < indexThreads.length; ++i) {
        assertTrue(client().prepareGet("index", "type", Integer.toString(i)).get().isExists());
    }
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) TypeMissingException(org.elasticsearch.indices.TypeMissingException) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)

Example 5 with GetMappingsResponse

use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse in project elasticsearch by elastic.

the class DynamicMappingTests method testTypeNotCreatedOnIndexFailure.

public void testTypeNotCreatedOnIndexFailure() throws IOException, InterruptedException {
    XContentBuilder mapping = jsonBuilder().startObject().startObject("_default_").field("dynamic", "strict").endObject().endObject();
    IndexService indexService = createIndex("test", Settings.EMPTY, "_default_", mapping);
    try {
        client().prepareIndex().setIndex("test").setType("type").setSource(jsonBuilder().startObject().field("test", "test").endObject()).get();
        fail();
    } catch (StrictDynamicMappingException e) {
    }
    GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").get();
    assertNull(getMappingsResponse.getMappings().get("test").get("type"));
}
Also used : IndexService(org.elasticsearch.index.IndexService) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)

Aggregations

GetMappingsResponse (org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)26 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)11 Map (java.util.Map)8 PutMappingResponse (org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)6 SearchResponse (org.elasticsearch.action.search.SearchResponse)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 IOException (java.io.IOException)4 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Client (org.elasticsearch.client.Client)2 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)2 TypeMissingException (org.elasticsearch.indices.TypeMissingException)2 ObjectObjectCursor (com.carrotsearch.hppc.cursors.ObjectObjectCursor)1 ReadContext (com.jayway.jsonpath.ReadContext)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1