0
点赞
收藏
分享

微信扫一扫

【Minecraft开服教学】使用 MCSM 面板一键搭建我的世界服务器 并使用内网穿透公网远程联机

八卦城的酒 2023-05-27 阅读 101

目录

索引index

定制分词器

Type底层结构及弃用原因

定制 dynamic mapping

定制dynamic mapping template 动态映射模板

零停机重建索引

生产环境应该度别名数据


索引index

Put /index

Stings 分片

Mapping 映射

Aliases 别名

增加

Put my_index2

{

       "settings":{

          "number_of_shards":3,

          "number_of_replicas":1

  },

  "mappings":{

    "properties":{

      "name":{"type":"text"}

    }

  },

  "aliases":{

    "default_index":{}

   

  }

}

Default_index 别名 也可以用来查询

Get default_index/_doc/1

获取索引信息

Get myindex

修改索引

 

删除必须设置索引名 防止 delete /_all 删除全部索引

 

定制分词器

delete my_inde

#定制分词器

put /my_index

{

  "settings":{

    "analysis":{

      "analyzer":{

        "es_std":{

          "type":"standard",

          "stopwords":"_english_"

        }

      }

    }

  }

}

#测试标准分词器

get /my_index/_analyze

{

  "analyzer":"standard",

  "text":"a dog is in the house helloword"

}

#测试自定义分词器

get /my_index/_analyze

{

  "analyzer":"es_std",

  "text":"a dog is in the house helloword"

}

delete /my_index

#定制分词器详细过程

#char_filter 预处理阶段 & 转and 分词器

#filter 停用词策略 the a 取消分词

#analyzer 定制分词器

# "char_filter":["html_strip","&_to_and"],  标签 分词器

put /my_index

{

  "settings":{

    "analysis":{

      "char_filter":{

        "&_to_and":{

          "type":"mapping",

          "mappings":["&=> and"]

        }

      },

      "filter":{

        "my_stopwords":{

          "type":"stop",

          "stopwords":["the","a"]

        }

      },

      "analyzer":{

        "my_analyzer":{

          "type":"custom",

          "char_filter":["html_strip","&_to_and"],

          "tokenizer":"standard",

          "filter":["lowercase","my_stopwords"]

        }

      }

    }

  }

}

#测试

#& 变成 and  the 消失  测试成功

get /my_index/_analyze

{

  "analyzer":"my_analyzer",

  "text":"a dog is & in the house helloword"

}

Type底层结构及弃用原因

预计Es 9 后彻底删除

Type 是索引中区分数据类型的

Es 存储type不同机制

 

对应俩种数据类型 存储方式

 

Es 底层存储结构

 

每条信息需要记录,浪费很多存储空间,统一索引下 有很多type没有值导致大量空值导致浪费空间

所以预计在es9后彻底删除这个字段

定制 dynamic mapping

定制 dynamic策略

#动态mapping映射状态 false 未设置字段不进入倒排索引

#没有定义的false 字段不会进入倒排索引

#有定义的按照定义的 会进入倒排索引

#可以插入新字段但是不会进入倒排索引,定义的会进入倒排索引

put myindex

{

  "mappings":{

    "dynamic":false,

    "properties":{

        "title":{"type":"text"},

        "address":{

          "type":"object",

          "dynamic":true

        }

    }

   

  }

}

没有动态映射的,通过中间词是无法查询的需要全文检索才可以

#必须标准字段,多余字段会报错无法存入

 "dynamic":strict,

#关闭日期探测,自动变成text类型“date_detection”:false

Put /myindex

{

“mappings”:{

       “date_detection”:false

}

}

Get /myindex/_maping

自定义日期格式

Put myindex

{

       "mappings":{

              "dynamic_date_formats":["yyyy-MM-dd"]

}

}

传来string 转换long 或float"numeric_detection":true

delete myindex

Put myindex

{

       "mappings" :{

              "numeric_detection":true

}

}

Put /myindex/_doc/1

{

"my_float":"1.0",

"my_long":"1"

}

get myindex/_doc/1

get /myindex/_mapping

 

定制dynamic mapping template 动态映射模板

delete myindex

#创建动态映射模板如果命中规则,使用此模板英文分词器

#*_en 结尾的使用text 存 英文分词器

put /myindex

{

  "mappings":{

    "dynamic_templates":[{

      "en":{

        "match":"*_en",

        "match_mapping_type":"string",

        "mapping":{

          "type":"text"

          ,"analyzer":"english"

        }

      }

    }]

  }

}

put /myindex/_doc/1

{"te":"this is my xx_en"}

put /myindex/_doc/4

{"tccsssse":"this is 中文my  "}

get myindex/_mapping

匹配规则

Match 属于什么

Unmatch 不属于什么

Match_mapping_type 属于什么类型

Path_match  路径匹配 *.xx 

Path_unmatch 路径不匹配

 

Norms false 指标评分因素

 

零停机重建索引

 

在线上运行的项目,发现不满足要求,创建新索引把旧数据放到新索引中去,从而实现重建索引

拷贝索引数据时间,则是停机不太好

//愿索引 date

Put /my_index

{

“mappings”:{

       “name”:{

              “type:”date”

}

}

}

//设置读取位置

Put /my_index/_alias/prod_index

//新索引

Put /my_index_new

{

“mappings”:{

       “name”:{

              “type:”text”

}

}

}

//切换别名值 程序读取别名

Post /_aliases

{

       “actions”:[

              {“remove”:{“index:”my_index”,”alias”:”prod_index”}}

{“add”:{“index:”my_index_new”,”alias”:”prod_index”}}

]

}

生产环境应该度别名数据

 

ok

持续更新

举报

相关推荐

0 条评论