【建表】ElasticSearch建表命令
使用google插件Postman
发送方式为PUT,url地址:
192.168.2.11:9200/IndexName
文本raw,数据为json格式
{
"settings":{
"number_of_shards":5,
"number_of_replicas":1
},
"mappings":{
"TypeName":{
"dynamic":"strict",
"properties":{
"tableId":{"type":"string","store":"yes","index":"not_analyzed"},
"title":{"type":"string","store":"yes","index":"analyzed","analyzer": "ik_max_word","search_analyzer": "ik_max_word"},
"author":{"type":"string","store":"yes","index":"analyzed","analyzer": "ik_max_word","search_analyzer": "ik_max_word"},
"summary":{"type":"string","store":"yes","index":"analyzed","analyzer": "ik_max_word","search_analyzer": "ik_max_word"},
"contextSrc":{"type":"string","store":"yes","index":"not_analyzed","ignore_above": 100},
"context":{"type":"string","store":"yes","index":"analyzed","analyzer": "ik_max_word","search_analyzer": "ik_max_word"},
"keywords":{"type":"string","store":"yes","index":"analyzed","analyzer": "ik_max_word","search_analyzer": "ik_max_word"},
"publishDate":{"type":"string","store":"yes","index":"not_analyzed"},
"createTime":{"type":"string","store":"yes","index":"not_analyzed"},
"modifyTime":{"type":"string","store":"yes","index":"not_analyzed"},
"deleteTime":{"type":"string","store":"yes","index":"not_analyzed"},
"url":{"type":"string","store":"yes","index":"not_analyzed"},
"isDeleted":{"type":"string","store":"yes","index":"not_analyzed"}
}
}
}
}
属性说明:
properties表示表的字段
- type字段类型,所有得字段都设置成了string,是因为在查询和编码过程中,有些类型不能很好的被转换,例如boolean
- store是否存储,属性有yes或者no,无论那种属性都会被存储,但如果设置成no,在查询的时候是无法用此属性作为查询项的,基于拓展和业务方便维护,建议使用yes
- index是否索引,属性有not_analyzed(分词不分析)、analyzed(分词分析)、no(不分析不分词)
- analyzer使用哪种分词器,在安装es的时候会自己安装分词器,例如IK分词器,在此指定分词的时候使用的是哪种分词器
- search_analyzer使用哪种分词器,但不是在入库的时候,而是在做查询的时候使用哪种分词器
- ignore_above对超过
ignore_above
的字符串,analyzer 不会进行处理;所以就不会索引起来。导致的结果就是最终搜索引擎搜索不到了。这个选项主要对not_analyzed
字段有用,这些字段通常用来进行过滤、聚合和排序。而且这些字段都是结构化的,所以一般不会允许在这些字段中索引过长的项。 - format日期格式要求,例如设置为"yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
dynamic表示是否使用动态映射,属性有
- true默认值,动态添加字段
- false忽略新字段
- strict如果碰到陌生字段,抛出异常
settings表示设置
- num_of_shards设置分片数量,默认为5
- num_of_replicas设置副本数量,默认为1