Elasticsearch 动态模板
Elasticsearch dynamic templating
我正在尝试让 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
从某种意义上说,我得到
{
"bigtestindex": {
"mappings": {}
}
}
看来我的 Sense 命令有点不正常,应该是
PUT /bigtestindex/_template/bigtesttemplate_1 (creates index and template in one command
或
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
在尝试了几件事后发现了这个,hth 其他人
更新
正如@avr 所说,您确实需要先创建模板,然后再创建索引,您也可以在同一个 PUT 语句中创建索引和模板。
它与确保您的 JSON
设置正确以匹配正确的 API 端点有关。 "mappings" 应该与设置分开,即
{
"settings" {
...
},
"mappings" {
...
}
}
没有
{
"settings" {
...
"mappings" {
}
}
"mappings" should NOT be included in the `"settings"` - needs to be separate.
hth,还有谁遇到同样的问题
首先你需要创建模板然后创建索引。您可以从 elasticsearch 文档中找到相同的内容。
Templates are only applied at index creation time. Changing a template will have no impact on existing indices.
我正在尝试让 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
从某种意义上说,我得到
{
"bigtestindex": {
"mappings": {}
}
}
看来我的 Sense 命令有点不正常,应该是
PUT /bigtestindex/_template/bigtesttemplate_1 (creates index and template in one command
或
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
在尝试了几件事后发现了这个,hth 其他人
更新 正如@avr 所说,您确实需要先创建模板,然后再创建索引,您也可以在同一个 PUT 语句中创建索引和模板。
它与确保您的 JSON
设置正确以匹配正确的 API 端点有关。 "mappings" 应该与设置分开,即
{
"settings" {
...
},
"mappings" {
...
}
}
没有
{
"settings" {
...
"mappings" {
}
}
"mappings" should NOT be included in the `"settings"` - needs to be separate.
hth,还有谁遇到同样的问题
首先你需要创建模板然后创建索引。您可以从 elasticsearch 文档中找到相同的内容。
Templates are only applied at index creation time. Changing a template will have no impact on existing indices.