【问题标题】:Elasticsearch dynamic templatingElasticsearch 动态模板
【发布时间】:2016-08-23 13:57:11
【问题描述】:

我正在尝试让 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": {}
   }
}

【问题讨论】:

    标签: elasticsearch indexing mapping


    【解决方案1】:

    我的 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
    

    在尝试了几件事后发现了这一点,其他人

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

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

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

    不是

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

    hth,其他人有同样的问题

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 是的,你是对的,但是 - 它不能解决问题 - 但这是正确的操作顺序
      • 这与您如何设置 json 以匹配正确的 API 端点有关。
      • 它不能解决问题是什么意思?我认为template 不存在 API 端点!
      • 您的解决方案在模板创建方面是正确的,但它没有解决映射问题。如果您查看问题中发布的 JSON,我正在尝试在模板中创建自动完成功能。映射问题已通过模板中的正确 JSON 结构解决
      • 哦.. 我没有观察到这一点,也很难找到 :) 。但是您的答案具有误导性,用于创建模板的正确命令是 PUT /_template/bigtesttemplate_1 NOT PUT /template/bigtesttemplate_1
      猜你喜欢
      • 1970-01-01
      • 2018-09-18
      • 2018-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-30
      相关资源
      最近更新 更多