zoukankan      html  css  js  c++  java
  • es Indices Administration 更新索引

    1.为了访问索引信息,使用adminClient

    IndicesAdminClient indicesAdminClient = client.admin().indices();
    

    2.创建索引

    client.admin().indices().prepareCreate("twitter").get();
    

    3. 设置索引参数

    client.admin().indices().prepareCreate("twitter")     
            .setSettings(Settings.builder()             
                    .put("index.number_of_shards", 3)
                    .put("index.number_of_replicas", 2)
            )
            .get();   
    
    

    4.PUT MAPPING

    client.admin().indices().prepareCreate("twitter")    
            .addMapping("_doc", "message", "type=text") 
            .get();
    Creates an index called twitter
    Add a _doc type with a field called message that has the datatype text.
    

    关于addMapping方法有很多种形式.可以使用 XContentBuilder 或者 Map参数.具体的请参考使用版本的javadoc来选择最适合你的方法。

    PUT mapping也可以用于更新已经创建的索引。如:

    client.admin().indices().preparePutMapping("twitter")   
    .setType("_doc")
    .setSource("{
    " +
            "  "properties": {
    " +
            "    "name": {
    " +                           
            "      "type": "text"
    " +
            "    }
    " +
            "  }
    " +
            "}", XContentType.JSON)
    .get();
    
    // You can also provide the type in the source document
    client.admin().indices().preparePutMapping("twitter")
    .setType("_doc")
    .setSource("{
    " +
            "    "_doc":{
    " +                            
            "        "properties": {
    " +
            "            "name": {
    " +
            "                "type": "text"
    " +
            "            }
    " +
            "        }
    " +
            "    }
    " +
            "}", XContentType.JSON)
    .get();
    
    Puts a mapping on existing index called twitter
    
    Adds a new field name to the mapping
    
    The type can be also provided within the source
    

    5. Refresh刷新

    // 1.刷新所有索引
    client.admin().indices().prepareRefresh().get(); 
     //2.刷新一个索引
    client.admin().indices()
            .prepareRefresh("twitter")               
            .get(); 
     //3. 刷新多个索引
    client.admin().indices()
            .prepareRefresh("twitter", "company")   
            .get(); 
    

    6.获取已存在的索引信息Settings

    GetSettingsResponse response = client.admin().indices()
            .prepareGetSettings("company", "employee").get();                           
    for (ObjectObjectCursor<String, Settings> cursor : response.getIndexToSettings()) { 
        String index = cursor.key;                                                      
        Settings settings = cursor.value;                                               
        Integer shards = settings.getAsInt("index.number_of_shards", null);             
        Integer replicas = settings.getAsInt("index.number_of_replicas", null);         
    }
    

    Get settings for indices company and employee
    Iterate over results
    Index name
    Settings for the given index
    Number of shards for this index
    Number of replicas for this index

    7.更新索引Settings

    client.admin().indices().prepareUpdateSettings("twitter")   
            .setSettings(Settings.builder()                     
                    .put("index.number_of_replicas", 0)
            )
            .get();
    

    参考链接

    es官网

  • 相关阅读:
    第五周 day5 python学习笔记
    第四周 day4 python学习笔记
    第三周 day3 python学习笔记
    常用屏幕分辨率
    学习可以借鉴的大牛们的网站
    jq动态控制样式的一些方法(批量控制样式,带参数控制样式)
    jq实现事件委托
    h5Css新加的一些新的属性
    css布局模型
    task_13
  • 原文地址:https://www.cnblogs.com/bigorang/p/11993791.html
Copyright © 2011-2022 走看看