我试图让ES(使用我使用ES v1.4.1)动态模板在我的本地计算机上工作,由于某种原因,"mappings"
不是包括在内呢?我首先使用简单的
PUT /bigtestindex (I'm using Sense plugin, not curl),
然后我跟着
PUT /_template/bigtestindex_1
{
"template": "big*",
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": "1",
"max_gram": "20",
"token_chars": [
"letter",
"digit"
]
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding",
"autocomplete_filter"
]
},
"whitespace_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding"
]
}
}
},
"mappings": {
"doc": {
"properties": {
"anchor": {
"type": "string"
},
"boost": {
"type": "string"
},
"content": {
"type": "string",
"analyzer": "whitespace_analyzer"
},
"digest": {
"type": "string"
},
"host": {
"type": "string"
},
"id": {
"type": "string"
},
"metatag.description": {
"type": "string",
"analyzer": "standard"
},
"metatag.keywords": {
"type": "string",
"analyzer": "standard"
},
"segment": {
"type": "string"
},
"title": {
"type": "string",
"index": "not_analyzed",
"fields": {
"autocomplete": {
"type": "string",
"index_analyzer": "autocomplete",
"search_analyzer": "whitespace_analyzer"
}
}
},
"tstamp": {
"type": "date",
"format": "dateOptionalTime"
},
"url": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
我没有收到任何错误,语法看起来是正确的,但当我做的事情
GET /bigtestindex/_mappings
在Sense中,我得到了
{
"bigtestindex": {
"mappings": {}
}
}
答案 0 :(得分:0)
看来我的Sense命令有点偏,应该是
PUT /bigtestindex/_template/bigtesttemplate_1 (creates index and template in one command
OR
PUT /_template/bigtesttemplate_1 (creates just template) thanks to @avr for pointing out my incorrect command (needed some fresh eyes)
而不是
PUT /bigtestindex/_template/bigtesttemplate_1
在尝试了几件事之后发现了这个,和其他人一起
UPDATE 正如@avr所说,你需要先创建模板然后再创建索引,你也可以在同一个PUT语句中创建索引和模板。
这与确保JSON
设置正确以匹配正确的API端点有关。 “映射”应与设置分开,即
{
"settings" {
...
},
"mappings" {
...
}
}
不是
{
"settings" {
...
"mappings" {
}
}
"mappings" should NOT be included in the `"settings"` - needs to be separate.
hth,其他人有同样的问题
答案 1 :(得分:0)
首先,您需要创建模板然后创建索引。您可以从elasticsearch文档中找到相同的内容。
模板仅在索引创建时应用。更改模板不会对现有索引产生影响。