zoukankan      html  css  js  c++  java
  • TransportClient 新建index,mappings dynamic_templates。

    public void createIndex(TransportClient client, String index){
            CreateIndexRequest request = new CreateIndexRequest(index);
            String setting =""
                    +"{"
                    +"        "number_of_shards": 3,"
                    +"        "number_of_replicas": 1,"
                    +"        "search_analyzer": "ik_max_word""
                    +"}";
            String mapping ="{"
                    +"            "dynamic_templates": ["
                    +"                {"
                    +"                    "strings": {"
                    +"                        "match": "*","
                    +"                        "match_mapping_type": "string","
                    +"                        "mapping": {"
                    +"                            "type": "string","
                    +"                            "analyzer": "ik_max_word","
                    +"                            "fields": {"
                    +"                                "raw": {"
                    +"                                    "type": "string","
                    +"                                    "index": "not_analyzed","
                    +"                                    "ignore_above": 256"
                    +"                                }"
                    +"                            }"
                    +"                        }"
                    +"                    }"
                    +"                }"
                    +"            ]"
                    +"        }";
                request.settings(setting).mapping("_default_", mapping);
                client.admin().indices().create(request);
        }
    POST  http://192.168.1.12:9200/test
    
    {
        "settings": {
            "number_of_shards": 3,
            "number_of_replicas": 1,
            "search_analyzer": "ik_max_word"
        },
        "mappings": {
            "_default_": {
                "dynamic_templates": [
                    {
                        "strings": {
                            "match": "*",
                            "match_mapping_type": "string",
                            "mapping": {
                                "type": "string",
                                "analyzer": "ik_max_word",
                                "fields": {
                                    "raw": {
                                        "type": "string",
                                        "index": "not_analyzed",
                                        "ignore_above": 2560
                                    }
                                }
                            }
                        }
                    }
                ]
            }
        }
    }
    {
        "settings": {
            "number_of_shards": 5,
            "number_of_replicas": 1,
            "search_analyzer": "ik_max_word"
        },
        "mappings": {
            "_default_": {
                "dynamic_templates": [
                    {
                        "strings": {
                            "match": "*",
                            "unmatch": "id",
                            "match_mapping_type": "string",
                            "mapping": {
                                "type": "string",
                                "analyzer": "ik_max_word",
                                "fields": {
                                    "raw": {
                                        "type": "string",
                                        "index": "not_analyzed",
                                        "ignore_above": 2560
                                    }
                                }
                            }
                        }
                    },
                    {
                        "integers": {
                            "match": "id",
                            "mapping": {
                                "type": "integer"
                            }
                        }
                    }
                ]
            }
        }
    }
  • 相关阅读:
    学习Bitmap,处理“海量”数据
    学习Trie树,处理“海量”数据
    学习KMP算法
    学习堆与栈内存分配方式
    学习继承和虚析构函数
    学习处理数组子集和的算法
    学习类中的const和static类型
    学习利用动态规划解决若干问题
    【MySQL】MySQL忘记root密码解决方案
    【API】短信通106端口验证短信的实现
  • 原文地址:https://www.cnblogs.com/zzt-lovelinlin/p/8578701.html
Copyright © 2011-2022 走看看