文档章节

【Elasticsearch】Indices APIs

HarryWu
 HarryWu
发布于 2016/04/11 14:36
字数 548
阅读 53
收藏 0

#程序员薪资揭榜#你做程序员几年了?月薪多少?发量还在么?>>>


一、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\n
optional_source\n
actiion_and_meta_data\n
optional_source\n
...
...
actiion_and_meta_data\n
optional_source\n

The possible actions are index,create,delete and update.

二、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
    }
  }
}'               ==>

三、Index Templates

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html

Index Templates 当你定义了一个template。新的indx创建时候,只有匹配到template的pattern string。该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 }
        }
    }}'


© 著作权归作者所有

HarryWu
粉丝 7
博文 153
码字总数 60358
作品 0
马鞍山
私信 提问
加载中

评论(0)

学习python库:elasticsearch-py

一、介绍 elasticsearch-py是一个官方提供的low-level的elasticsearch python客户端库。为什么说它是一个low-level的客户端库呢?因为它只是对elasticsearch的rest API接口做了一层简单的封装...

冷冰若水
01/01
0
0
Elasticsearch 6.4基本操作 - Java版

Elasticsearch Java API有四类client连接方式 TransportClient RestClient Jest Spring Data Elasticsearch 其中TransportClient和RestClient是Elasticsearch原生的api。TransportClient可以......

osc_5512k200
2018/11/21
27
0
Elasticsearch High Level REST Client

Compatibility The Java High Level REST Client requires Java 1.8 and depends on the Elasticsearch core project. The client version is the same as the Elasticsearch version that t......

osc_shz3aep4
2019/03/05
15
0
Elasticsearch Java API有四类client连接方式

Elasticsearch Java API有四类client连接方式 TransportClient RestClient Jest Spring Data Elasticsearch 其中TransportClient和RestClient是Elasticsearch原生的api。TransportClient可以......

osc_9yc7q9oq
03/14
6
0
prometheus 监控ElasticSearch核心指标

ES监控方案 本文主要讲述使用 Prometheus监控ES,梳理核心监控指标并构建 Dashboard ,当集群有异常或者节点发生故障时,可以根据性能图表以高效率的方式进行问题诊断,再对核心指标筛选添加...

osc_0zb4xeae
2019/07/09
4
0

没有更多内容

加载失败,请刷新页面

加载更多

文献速递20200524

一 文献题目:Characterizing the Causal Pathway for Genetic Variants Associated with Neurological Phenotypes Using Human Brain-Derived Proteome Data 不想看英文题目:使用人脑蛋白质......

osc_mbhfa1vl
40分钟前
9
0
【Java入门】JDK安装和环境变量配置(Win7版)

系统环境:Windows7 x64 安装JDK和JRE版本:1.8.0_191 1、下载JDK安装包 Oracle官网下载网址:https://www.oracle.com/technetwork/java/javase/downloads/index.html 选择需要下载的JDK版本...

osc_s7aj86hu
42分钟前
11
0
Android Q 指纹解锁流程

Android Q 指纹解锁流程 // Authentation Finger Schedule: (close Screen, Authentation with finger(Success))        // PhoneWindowManager        mKeyguardDelegate.onStar......

osc_0qnrwmy3
43分钟前
12
0
List的扩容机制,你真的明白吗?

一:背景 1. 讲故事 在前一篇大内存排查中,我们看到了Dictionary正在做扩容操作,当时这个字典的count=251w,你把字典玩的66飞起,其实都是底层为你负重前行,比如其中的扩容机制,当你遇到...

osc_34b9n45c
45分钟前
14
0
2020.04.12软件更新公告

原创软件区升级ComicsViewer、DjVuToy、Pdg2Pic、PdgRenamer、PdgThumbViewer

osc_6tgtqi6v
45分钟前
23
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部