2016-04-28 167 views
0

我試圖讓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": {} 
    } 
} 

回答

0

看來我的感覺命令是有點過了,應該已經

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. 

心連心,其他任何人有同樣的問題

0

首先,你需要創建模板,然後創建索引。您可以從elasticsearch文檔中找到相同的內容。

模板僅適用於索引創建時。更改模板將不會影響現有的索引。

+0

是的,你是正確的,但是 - 它不能解決問題 - 但這是正確的行動順序 – user3125823

+0

它有更多的關於如何讓json設置匹配適當的API端點。 – user3125823

+0

_it是什麼意思不解決probelm_?我不認爲用'template'存在API端點! – avr