简体   繁体   English

Elasticsearch动态模板

[英]Elasticsearch dynamic templating

I'm trying to get ES's (using I'm using ES v1.4.1) dynamic templating to work on my local machine and for some reason the "mappings" are not being included? 我正在尝试让ES的动态模板(使用ES v1.4.1)在我的本地计算机上工作,并且由于某种原因未包括"mappings" I first create the index with a simple 我首先用一个简单的索引

PUT /bigtestindex (I'm using Sense plugin, not curl), 

then I follow that with 然后我跟着

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"
              }
            }
          }
        }
      }
    }

I'm not receiving any errors and the syntax looks to be correct but when I do something like 我没有收到任何错误,语法看起来是正确的,但是当我执行类似的操作时

GET /bigtestindex/_mappings

in Sense, I get 从某种意义上说,我明白了

    {
   "bigtestindex": {
      "mappings": {}
   }
}

It seems my Sense command was a bit off, should have been 看来我的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)

instead of 代替

PUT /bigtestindex/_template/bigtesttemplate_1

discovered this after trying several things, hth someone else 在尝试了几件事之后发现了这个,还有其他人

UPDATE As @avr stated, you do need to create the template first and then the index, you can create the index and the template in the same PUT statement as well. UPDATE正如@avr所述,您确实需要先创建模板,然后再创建索引,还可以在同一PUT语句中创建索引和模板。

It has everything to do with making sure your JSON is setup properly to match the right API endpoints. 它与确保正确设置JSON以匹配正确的API端点有关。 "mappings" should be separate from settings ie “映射”应与设置分开,即

{
"settings" {
...
},
 "mappings" {
...
 }
}

NOT

{
"settings" {
...
"mappings" {
 }
}

"mappings" should NOT be included in the `"settings"` - needs to be separate.

hth, anyone else having the same problem hth,其他任何有同样问题的人

First you need to create template then create index. 首先,您需要创建模板,然后创建索引。 You can find the same from elasticsearch documentation. 您可以从elasticsearch文档中找到相同的内容。

Templates are only applied at index creation time. 模板仅在创建索引时应用。 Changing a template will have no impact on existing indices. 更改模板不会对现有索引产生影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM