繁体   English   中英

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

在尝试了几件事之后发现了这个,还有其他人

UPDATE正如@avr所述,您确实需要先创建模板,然后再创建索引,还可以在同一PUT语句中创建索引和模板。

它与确保正确设置JSON以匹配正确的API端点有关。 “映射”应与设置分开,即

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

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

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

hth,其他任何有同样问题的人

首先,您需要创建模板,然后创建索引。 您可以从elasticsearch文档中找到相同的内容。

模板仅在创建索引时应用。 更改模板不会对现有索引产生影响。

暂无
暂无

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

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