Elasticsearch动态模板

问题描述:

我试图让ES(使用我使用ES v1.4.1)动态模板工作在我的本地机器上,由于某些原因"mappings"没有被包含在内?我先用一个简单的Elasticsearch动态模板

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

看来我的感觉命令是有点过了,应该已经

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所说,你d o需要首先创建模板,然后创建索引,然后可以在相同的PUT语句中创建索引和模板。

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

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

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

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

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

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

模板仅适用于索引创建时。更改模板将不会影响现有的索引。

+0

是的,你是正确的,但是 - 它不能解决问题 - 但这是正确的行动顺序 – user3125823

+0

它有更多的关于如何让json设置匹配适当的API端点。 – user3125823

+0

_it是什么意思不解决probelm_?我不认为用'template'存在API端点! – avr