Serge Huber created UNOMI-130:
---------------------------------

             Summary: Use index templates to create new indexes with default 
mappings instead of Java code
                 Key: UNOMI-130
                 URL: https://issues.apache.org/jira/browse/UNOMI-130
             Project: Apache Unomi
          Issue Type: Improvement
          Components: core
    Affects Versions: 1.3.0-incubating
            Reporter: Serge Huber
            Assignee: Serge Huber
             Fix For: 1.3.0-incubating


We use some Java code to insert default mappings and settings into 
automatically created indexes. But with ES 5.0 it is now possible to use index 
templates. We should therefore replace our custom code to use index templates, 
making maintenance and configuration of the templates a lot easier.

See : 
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html

Basically this would allow us to replace something like this (from 
ElasticSearchPersistenceServiceImpl.java) : 

{code}
    private void internalCreateIndex(String indexName, Map<String, String> 
mappings) {
        CreateIndexRequestBuilder builder = 
client.admin().indices().prepareCreate(indexName)
                .setSettings("{\n" +
                        "    \"index\" : {\n" +
                        "        \"number_of_shards\" : " + numberOfShards + 
",\n" +
                        "        \"number_of_replicas\" : " + numberOfReplicas 
+ "\n" +
                        "    },\n" +
                        "    \"analysis\": {\n" +
                        "      \"analyzer\": {\n" +
                        "        \"folding\": {\n" +
                        "          \"type\":\"custom\",\n" +
                        "          \"tokenizer\": \"keyword\",\n" +
                        "          \"filter\":  [ \"lowercase\", 
\"asciifolding\" ]\n" +
                        "        }\n" +
                        "      }\n" +
                        "    }\n" +
                        "}\n");

        for (Map.Entry<String, String> entry : mappings.entrySet()) {
            builder.addMapping(entry.getKey(), entry.getValue());
        }

        builder.execute().actionGet();
        existingIndexNames.add(indexName);

    }
{code}

to simply use something like this : 

{code}
{
  "template": "te*",
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "type1": {
      "_source": {
        "enabled": false
      },
      "properties": {
        "host_name": {
          "type": "keyword"
        },
        "created_at": {
          "type": "date",
          "format": "EEE MMM dd HH:mm:ss Z YYYY"
        }
      }
    }
  }
}
{code}




--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to