1

I have a conceptual entity called test execution and every test execution should be a separate type in an Elasticsearch index. Mapping for every test execution type should be the same and will be added to the index dynamically.

I have already created a mapping for a single test execution as follows and I want to make it generalized for all the types that will be created in future.

PUT /test_tool/_mapping/test_execution_20151710_1324_12
{
    "properties": {
        "timestamp":{
            "type": "string",
            "index": "not_analyzed"
        },
        "source":{
            "type": "string",
            "index": "not_analyzed"
        },
            "payload":{
            "type": "string",
            "index": "not_analyzed"
        }
    }
}

How should I create a generic mapping for dynamic types, for an example: create a wildcard for the type 'test_execution_*'.

[Update]

After looking at the below answers I have considered not to use separate types for different executions and hope to use a separate key to identify documents in the same test execution.

PUT /test_tool/_mapping/executions
{
    "properties": {
        "timestamp":{
            "type": "string",
            "index": "not_analyzed"
        },
        "source":{
            "type": "string",
            "index": "not_analyzed"
        },
            "payload":{
            "type": "string",
            "index": "not_analyzed"
        },
            "test_execution":{
            "type": "string",
            "index": "not_analyzed"
        }
    }
}

2 Answers 2

2

What you need is to use a template, from official docs:

   PUT _template/template_1
{
  "template": "test_too*",
  "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"
        }
      }
    }
  }
}

Defines a template named template_1, with a template pattern of te*. The settings and mappings will be applied to any index name that matches the te* pattern.

So in your case you'll want to use something like: "template": "test_to*"

Sign up to request clarification or add additional context in comments.

7 Comments

In your sample, the index has the wildcard, what I want is the dynamic type.
when yo mean type is the document type right? So this is what happens, whenever you create a new type with the index called anything that starts with test_execution_ , the mapping used in the template will be automatically applied. If this is not what you're looking for, please edit your question to make what you want clearer.
Sorry if I misunderstood, please correct me if I am wrong. In my case, I have a non-changing index called 'test_tool' and it should contain types which have the pattern 'test_execution_*". Is that what you mean?
oh.. ok, my bad I missed that.. so in your case you just have to create the template like 'test_*' and any types you create under that index they will have the template mapping applied to them automatically, but the approach is the same.
From what I understood, what you say is that any type I put in the created index would have the given mapping. If this is true, how is the type name hard coded to 'type1'
|
1

I am not sure if it is a great idea to have an own type for each execution (I would refrain from it), as this will explode your mapping.

You could implement this, using the _default_ type in an index template, see the docs.

However types will go away over the next releases of Elasticsearch so maybe you want to rethink that strategy.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.