【Elasticsearch】Indices APIs

5244 단어
하나, Bulk API
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
The bulk API makes it possible to perform many index/delete operations in a single API call. This can greatly increate the indexing speed.
The REST API endpoint is/_bulk ,and it expects the following JSON structure:
actiion_and_meta_data
optional_source
actiion_and_meta_data
optional_source
... ... actiion_and_meta_data
optional_source

The possible actions are index,create,delete and update.
2. Put Mapping
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html
Put Mapping API는 존재하는 Index를 위해 새로운 Type을 만들거나 존재하는 Type을 위해 새로운 Fields를 만들 수 있습니다.(The Put mapping API allows you to add a new type on an existing index,or new fields to an existing type)
curl -XPUT 'http://localhost:9200/twitter' -d '{       
  "mappings": {
    "tweet": {
      "properties": {
        "message": {
          "type": "string"
        }
      }
    }
  }
}'                            ==>  Index:twitter, Type:tweet, Fields:message

curl -XPUT 'http://localhost:9200/twitter/_mapping/tweet' -d '{
  "properties": {
    "user_name": {
      "type": "string"
    }
  }
}'                            ==>  Type:tweet, Fields:user_name

curl -XPUT 'http://localhost:9200/twitter/_mapping/user' -d '{
  "properties": {
    "name": {
      "type": "string"
    }
  }
}'                            ==>  Index:twitter, Type:user, Fields:name

Multi-Index:
curl -XPUT 'http://localhost:9200/my_index' -d '{
  "mappings": {
    "user": {
      "properties": {
        "name": {
          "properties": {
            "first": {
              "type": "string"
            }
          }
        },
        "user_id": {
          "type": "string",
          "index": "not_analyzed"
        }
      }
    }
  }
}'                ==> Index:my_index, Type:user。Type:user Fields:name,first


curl -XPUT 'http://localhost:9200/my_index/_mapping/user' -d '{
  "properties": {
    "name": {
      "properties": {
        "last": {                ==>  Fields properties
          "type": "string"
        }
      }
    },
    "user_id": {
      "type": "string",
      "index": "not_analyzed",
      "ignore_above": 100        ==>  ignore_above 0 100
    }
  }
}'               ==>

3. Index Templates
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html
Index Templates 템플릿을 정의할 때새 indx를 만들 때template에 일치하는patternstring만 있습니다.이template의settings,mappings,alias 정의는 새로 만든 index에 적용됩니다.(Index Templates allow you to define templates that will automatically be applied when new indices are created.The templates include both settings and mappings and a simple pattern template that controls whether the templates should be applied to the new index.)
Note: Templates are only applied at index creation time.Changing a template will have no impact on existsing indices.
curl -XPUT 'localhost:9200/_template/template_1' -d 
'{
  "template": "te*",        ==> pattern
  "mappings": {
    "type1": {
      "_source": {
        "enabled": false
      },
      "properties": {
        "host_name": {
          "type": "string",
          "index": "not_analyzed"
        },
        "create_at": {
          "type": "date",
          "format": "EEE MMM dd HH:mm:ss Z YYYY"
        }
      }
    }
  }
}'        ==> Define a template named template_1,with a template pattern of te*.The mappings will be applied to any index name that matches the te* template

Multiple Template Matching:
Multiple index templates can potentially match an index,in this case,both the settting and mappings are merged into the final ocnfiguration of the index.The order of the merging can be controlled useing order parameter,with lower order being applied first, and higher orders overriding them.
curl -XPUT localhost:9200/_template/template_1 -d '{
    "template" : "*",
    "order" : 0,
    "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
        "type1" : {
            "_source" : { "enabled" : false }
        }
    }}'

curl -XPUT localhost:9200/_template/template_2 -d '{
    "template" : "te*",
    "order" : 1,
    "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
        "type1" : {
            "_source" : { "enabled" : true }
        }
    }}'

좋은 웹페이지 즐겨찾기