簡體   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