Open Distro for Elasticsearch does not use template in index creation

I am using Open Distro for Elasticsearch, version 1.9.0.
I executed

curl -ivvk -H "Content-Type: application/json" -H "Accept: application/json" -u username:password -X PUT "https://localhost:9200/_template/test_template" -d '
{
  "index_patterns": ["test-*"],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "index.refresh_interval": "5s"
    },
    "mappings": {
      "properties": {
        "status": {
    	  "type": "keyword"
        },
       "message": {
    	  "type": "text"
	}
      }
    }
  }
}'

HTTP/1.1 200 OK

{"acknowledged":true}

curl -ivvk -H "Accept: application/json" -u username:password -X GET "https://localhost:9200/_cat/templates"

HTTP/1.1 200 OK

[{"name":"test_template","index_patterns":"[test-*]","order":"0","version":null,"composed_of":""}]

I then created the index, test-1, with a deliberate attempt to violate the intended mapping of status to keyword, by assigning an integer value to it:

curl -ivvk -H "Content-Type: application/json" -H "Accept: application/json" -u username:password -X POST "https://localhost:9200/test-1/_create/1" -d '
{
  "status": 7,
  "message": "This is a test."
}'

HTTP/1.1 201 Created

{"_index":"test-1","_type":"_doc","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}

When I inspected the mapping that was applied to test-1, I saw:

curl -ivvk -u username:password -H "Accept: application/json" "https://localhost:9200/test-1/_mapping?pretty"

HTTP/1.1 200

{
  "test-1" : {
    "mappings" : {
      "properties" : {
        "message" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "status" : {
          "type" : "long"
        }
      }
    }
  }
}

I realized the template was ignored since status had type, long, instead of keyword. Can someone tell me what I should be doing?

Hello @hweber, I tried to follow your steps and did just a first one. After I tried to see created template:

Create template

curl -ivvk -H "Content-Type: application/json" -H "Accept: application/json" -X PUT "http://localhost:9200/_template/test_template" -d '
{
  "index_patterns": ["test-*"],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "index.refresh_interval": "5s"
    },
    "mappings": {
      "properties": {
        "status": {
      "type": "keyword"
        },
       "message": {
      "type": "text"
}
      }
    }
  }
}'

Get template

curl http://localhost:9200/_template/test_template?pretty
{
  "test_template" : {
    "order" : 0,
    "index_patterns" : [
      "test-*"
    ],
    "settings" : { },
    "mappings" : { },
    "aliases" : { }
  }
}

It is Open Distro 1.7.0. We have some templates and they works but I created one from the file using the following steps:

Create template json

vi nginx-access.json

{
    "order" : 0,
    "version" : 60001,
    "index_patterns" : [
      "nginx-access*"
    ],
    "settings" : {
      "index" : {
        "number_of_shards" : "1",
        "refresh_interval" : "5s"
      }
    },
    "mappings" : {
      "dynamic_templates" : [
        {
          "message_field" : {
            "path_match" : "message",
            "mapping" : {
              "norms" : false,
              "type" : "text"
            },
            "match_mapping_type" : "string"
          }
        },
        {
          "string_fields" : {
            "mapping" : {
              "norms" : false,
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "ignore_above" : 256,
                  "type" : "keyword"
                }
              }
            },
            "match_mapping_type" : "string",
            "match" : "*"
          }
        }
      ],
      "properties" : {
        "@timestamp" : {
          "type" : "date"
        },
        "@version" : {
          "type" : "keyword"
        },
        "geoip" : {
          "dynamic" : true,
          "properties" : {
            "ip" : {
              "type" : "ip"
            },
            "latitude" : {
              "type" : "half_float"
            },
            "location" : {
              "type" : "geo_point"
            },
            "longitude" : {
              "type" : "half_float"
            }
          }
        },
        "ng_real_ip" : {
          "type" : "ip"
        },
        "ng_remote_addr" : {
          "type" : "ip"
        },
        "ng_request_time" : {
          "type" : "long"
        },
        "ng_request_length" : {
          "type" : "long"
        },
        "ng_bytes_sent" : {
          "type" : "long"
        },
        "ng_upstream_connect_time" : {
          "type" : "long"
        },
        "ng_upstream_response_time" : {
          "type" : "long"
        }
      }
    },
    "aliases" : { }
  }
}

Upload template

curl -XPUT http://localhost:9200/_template/nginx-access?pretty -H 'Content-Type: application/json' -d @nginx-access.json

I want to say that it works and in such a case we just should set it correctly via request, like you do it.

Thank you! It appears that the “template” name/value in my test_template caused the problem. When I removed it to make it look like your nginx-access.json it worked.

1 Like