dynamic mapping配置放到template使用问题

来源:4-13 -索引模板.mp4

慕村7052289

2018-12-05

老师您好,我使用如下配置创建test2模板、test_d1模板、t8_index的时候,t8_index匹配到test2模板了,没有匹配到test_d1模板,但是test_d1模板的order值比test2要大,应该优先匹配test_d1才对吧,不知道问题在哪里 请老师帮忙解答



PUT _template/test_d1
{
  "index_patterns":["*_index","index_t*"],
  "order":3,
  "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
      "doc" : {
        "_source" : {
          "enabled" : true
        },
        "dynamic_templates": [
          {
           "custom_string_to_keyword": {
            "match_mapping_type": "string",
            "mapping": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
        ]
      }
    }
  
}


PUT _template/test2
{
  "index_patterns":["*_index","index_t*"],
  "order":2,
  "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
      "doc" : {
        "_source" : {
          "enabled" : true
        },
        "properties" : {
          "age" : {
            "type" : "integer"
          },
          "city" : {
            "type" : "keyword"
          },
          "name" : {
            "type" : "keyword"
          },
          "title" : {
            "type" : "text"
          }
        }
      }
    }
  
}


PUT t8_index/doc/1
{
  "title": "t8",
  "city": "shenzhen",
  "name": "Smith2",
  "age": 12
}



写回答

3回答

rockybean

2018-12-06

你期待的是指应用test_d1吗?实际不是这样的,template在匹配到多个时会做一个合并处理,合并时如果发现多个模板设置了同一个key,那就取order值大的。你这里从dynamic template来看test-d1实际生效了

0
1
慕村7052289
感谢老师提点,我看了一下合并后的mapping,如果有指定字段值,就匹配properties中指定的字段值,如果没有指定就从动态模板获取
2018-12-06
共1条回复

慕村7052289

提问者

2018-12-06

GET t8_index/_mapping

{

  "t8_index" : {

    "mappings" : {

      "doc" : {

        "dynamic_templates" : [

          {

            "custom_string_to_keyword" : {

              "match_mapping_type" : "string",

              "mapping" : {

                "ignore_above" : 256,

                "type" : "keyword"

              }

            }

          }

        ],

        "properties" : {

          "age" : {

            "type" : "integer"

          },

          "city" : {

            "type" : "keyword"

          },

          "name" : {

            "type" : "keyword"

          },

          "title" : {

            "type" : "text"

          }

        }

      }

    }

  }

}



GET t8_index/_settings

{

  "t8_index" : {

    "settings" : {

      "index" : {

        "creation_date" : "1544008166309",

        "number_of_shards" : "1",

        "number_of_replicas" : "1",

        "uuid" : "IWBeHlNhSwWs9vNml1TQ-Q",

        "version" : {

          "created" : "6050199"

        },

        "provided_name" : "t8_index"

      }

    }

  }

}


GET t8_index/_search

{

  "took" : 0,

  "timed_out" : false,

  "_shards" : {

    "total" : 1,

    "successful" : 1,

    "skipped" : 0,

    "failed" : 0

  },

  "hits" : {

    "total" : 1,

    "max_score" : 1.0,

    "hits" : [

      {

        "_index" : "t8_index",

        "_type" : "doc",

        "_id" : "1",

        "_score" : 1.0,

        "_source" : {

          "title" : "t8",

          "city" : "shenzhen",

          "name" : "Smith2",

          "age" : 12

        }

      }

    ]

  }

}



0
0

rockybean

2018-12-05

你GET t8_index 我看下你创建索引后的配置

0
1
慕村7052289
配置信息如上条回复补充内容
2018-12-06
共1条回复

Elastic Stack从入门到实践,动手搭建数据分析系统

有了Elastic Stack,不用写一行代码,你也可以玩转大数据分析!

1361 学习 · 397 问题

查看课程