使用ElasticSearch-Head创建业务上需要的索引(索引名字,类型,是否分词)
- 打开ElasticSearch-Head,点击符合查询
其中在查询下,第一行输入地址,专门建立索引的地址,第二行输入索引的名字,右边有put,get,post,delete,先说put,建立索引时候使用,下面的代码写完执行put,会出现
证明建立成功。
建立时候怎么写这些代码
- 首先需要知道都使用那些字段,比如标题需要分词,那么就可以叫case_title_t,他的类型是text(文本),所以在case_title的后面使用缩写就可以:_t。使用分词需要在里面加:分词类型"analyzer": "simple_analyzer",类型:"type": "text",存储文档ID"index_options": "offsets"
- 日期类型的索引:使用_dt为后缀,类型是date,格式为"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",
- 关键字类型:使用keyword存储关键字类型的数据,比如状态为1或者0这样的数据,使用keyword
- 要给这个索引起别名的话,加上"aliases"
- 剩下的就是一些setting配置
- "settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"search": {
"slowlog": {
"level": "info",
"threshold": {
"fetch": {
"warn": "2s",
"trace": "200ms",
"debug": "500ms",
"info": "1s"
},
"query": {
"warn": "2s",
"trace": "200ms",
"debug": "500ms",
"info": "1s"
}
}
}
},
"indexing": {
"slowlog": {
"threshold": {
"index": {
"warn": "2s",
"trace": "200ms",
"debug": "500ms",
"info": "1s"
}
},
"source": "1000"
}
},
"analysis": {
"analyzer": {
"index_analyzer": {
"tokenizer": "tok_index"
},
"simple_analyzer": {
"tokenizer": "tok_simple"
}
},
"tokenizer": {
"tok_index": {
"type": "hanlp_index",
"enable_stop_dictionary": "true"
},
"tok_simple": {
"type": "hanlp_simple_num",
"enable_stop_dictionary": "true"
}
}
},
"number_of_shards": "1",
"number_of_replicas": "1"
} - "routing": 这个配置可以用来指定搜索请求路由到哪些节点,通过"_tier_preference"属性可以确定首选节点所在的分片。
- "search": 这个配置用于设置搜索日志的级别和阈值,阈值是指查询、获取过慢时打印信息的阀值,单位是毫秒。
- "indexing": 这个配置用于设置索引过慢时的日志级别和阈值,阈值是指索引操作过慢时打印信息的阀值,单位是毫秒。
- "analysis": 这个配置用于设置分析器及其配置,包括分词器、过滤器、正则表达式等。
- "number_of_shards": 这个配置用于设置索引的分片数量,默认为5。
- "number_of_replicas": 这个配置用于设置索引的副本数量,默认为1。
- 以上是这个配置文件中的大部分内容,其中"number_of_shards"和"number_of_replicas"有默认值,所以在这里指定了这两个参数之后,Elasticsearch依然会使用这些默认值。其他配置会根据具体的情况变化,根据实际需求进行配置即可。
来一份总体的代码吧!!!
{
"aliases": {
"case_management_info": {}
},
"mappings": {
"dynamic": "false",
"properties": {
"punish_classification_name_t": {
"type": "keyword"
},
"case_title_t": {
"type": "text",
"index_options": "offsets",
"analyzer": "simple_analyzer"
},
"document_number_t": {
"type": "keyword"
},
"business_classification_id_txt": {
"type": "keyword"
},
"business_classification_name_t": {
"type": "keyword"
},
"target_classification_id_txt": {
"type": "keyword"
},
"case_content_t": {
"type": "text",
"index_options": "offsets",
"analyzer": "simple_analyzer"
},
"punish_classification_id_txt": {
"type": "keyword"
},
"target_classification_name_t": {
"type": "keyword"
},
"issue_date_dt": {
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",
"type": "date"
},
"case_sorttitle_t": {
"type": "keyword"
},
"punish_date_dt": {
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",
"type": "date"
},
"publish_status_k": {
"type": "keyword"
},
"id": {
"type": "keyword"
},
"issue_organ_t": {
"type": "keyword"
},
"notice_date_dt": {
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",
"type": "date"
},
"company_name_t": {
"type": "keyword"
},
"company_code_t": {
"type": "keyword"
},
"publication_all_flag_k":{
"type":"keyword"
},
"visible_groups_txt": {
"type": "text"
},
"visible_users_txt": {
"type": "text"
},
"visible_depts_txt": {
"type": "text"
},
"visible_roles_txt": {
"type": "text"
}
}
},
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"search": {
"slowlog": {
"level": "info",
"threshold": {
"fetch": {
"warn": "2s",
"trace": "200ms",
"debug": "500ms",
"info": "1s"
},
"query": {
"warn": "2s",
"trace": "200ms",
"debug": "500ms",
"info": "1s"
}
}
}
},
"indexing": {
"slowlog": {
"threshold": {
"index": {
"warn": "2s",
"trace": "200ms",
"debug": "500ms",
"info": "1s"
}
},
"source": "1000"
}
},
"analysis": {
"analyzer": {
"index_analyzer": {
"tokenizer": "tok_index"
},
"simple_analyzer": {
"tokenizer": "tok_simple"
}
},
"tokenizer": {
"tok_index": {
"type": "hanlp_index",
"enable_stop_dictionary": "true"
},
"tok_simple": {
"type": "hanlp_simple_num",
"enable_stop_dictionary": "true"
}
}
},
"number_of_shards": "1",
"number_of_replicas": "1"
}
}
}