'dynamic templates'에 해당되는 글 1건

  1. 2014.12.04 [Elasticsearch] simple dynamic template 테스트

[Elasticsearch] simple dynamic template 테스트

Elastic/Elasticsearch 2014. 12. 4. 18:01


[Setting 설정]

{

"settings" : {

"number_of_shards" : 3,

"number_of_replicas" : 0

}

}


- 생성

curl -XPUT 'http://localhost:9200/dynamic_template -d @setting.json


[Mapping 설정]

{

"_source" : {

"enabled" : "true"

},

"_all" : {

"enabled" : "false"

},

        "dynamic_templates": [

        {

            "string_match": {

                "mapping": {

                    "index": "not_analyzed",

                    "type": "string"

                },

                "match_mapping_type": "string",

                "match": "*"

            }

        }

      ],

     "properties" : {}

}


- 생성

curl -XPUT http://localhost:9200/dynamic_template/test1/_mapping -d @mapping.json

curl -XPUT http://localhost:9200/dynamic_template/test2/_mapping -d @mapping.json


[Add document]

curl -XPOST http://127.0.0.1:9200/dynamic_template/test1 -d '{"docid" : "1"}'

curl -XPOST http://127.0.0.1:9200/dynamic_template/test2 -d '{"docid" : 1}'



이후 test1과 test2에 설정된 docid 필드에 대한 type을 확인을 해보면 아래와 같이 나오게 된다.


{

   "dynamic_template": {

      "mappings": {

         "test2": {

            "dynamic_templates": [

               {

                  "string_match": {

                     "mapping": {

                        "index": "not_analyzed",

                        "type": "string"

                     },

                     "match": "*",

                     "match_mapping_type": "string"

                  }

               }

            ],

            "_all": {

               "enabled": false

            },

            "properties": {

               "docid": {

                  "type": "long"

               }

            }

         },

         "test1": {

            "dynamic_templates": [

               {

                  "string_match": {

                     "mapping": {

                        "index": "not_analyzed",

                        "type": "string"

                     },

                     "match": "*",

                     "match_mapping_type": "string"

                  }

               }

            ],

            "_all": {

               "enabled": false

            },

            "properties": {

               "docid": {

                  "index": "not_analyzed",

                  "type": "string"

               }

            }

         }

      }

   }

}



: