-
constantScoreQuery
:当我们不关心检索词频率TF(Term Frequency)对搜索结果排序的影响时,可以使用constant_score将查询语句query或者过滤语句filter包装起来GET yzj_dev_stl_bill_de/_search { "query": { "constant_score": { "filter": { "bool": { "term": { "FIELD": { "value": "VALUE" } } } }, "boost": 1.0 } } } //--------------------------------------------------------- SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery(); boolBuilder.filter(QueryBuilders.termQuery("FIELD", "value")); ConstantScoreQueryBuilder constantScoreQueryBuilder = QueryBuilders.constantScoreQuery(boolBuilder); searchSourceBuilder.query(constantScoreQueryBuilder); SearchRequest searchRequest = new SearchRequest("test_index").source(searchSourceBuilder); SearchResponse search = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
-
删除索引:
DELETE /index_name
-
删除索引全部数据:
POST index_name/_delete_by_query { "query": { "match_all": {} } }
-
根据条件删除:
POST index_name/_delete_by_query { "query":{ "term":{ "_id":"ed157ec1c4f5471ba79223c798752183" } } }
-
获取索引基本状态信息,包括索引内数据条数:
GET index_name/_stats
-
查看某个索引的mapping:
GET index_name/_mapping
-
调整ES的
refresh_interval
间隔时间:## -1s表示不刷新,1s表示1秒刷新一次 PUT index_name { "settings": { "refresh_interval": "1s" } }
-
调整ES的
replica shard
数量:PUT /index_name/_settings { "number_of_replicas" : 2 }
-
创建一个索引模板,可以用于后续创建索引方便:
//查看索引模板 GET /_template/test //创建索引模板 PUT _template/test { "template": "*", 匹配所有索引 "order": 0, 优先级 "settings": { "index": { "number_of_replicas": "0", "number_of_shards": "3", "refresh_interval": "5s" } }, "mappings": { "_default_": { "dynamic_templates": [ { "message_field": { "path_match": "message", "mapping": { "norms": false, "type": "text" }, "match_mapping_type": "string" } }, { "string_fields": { "mapping": { "norms": false, "type": "text", "fields": { "keyword": { "type": "keyword" } } }, "match_mapping_type": "string", "match": "*" } } ], "_all": { "norms": false, "enabled": true }, "properties": { "@timestamp": { "include_in_all": false, "type": "date" }, "geoip": { "dynamic": true, "properties": { "ip": { "type": "ip" }, "latitude": { "type": "half_float" }, "location": { "type": "geo_point" }, "longitude": { "type": "half_float" } } }, "@version": { "include_in_all": false, "type": "keyword" } } } }, "aliases": {} }
-
测试分词
GET /_analyze { "text": ["测试文本"], "analyzer": "ik_max_word" }
在指定的分词器中查看分词结果
Elasticsearch的各种用法记录
于 2021-09-26 16:35:43 首次发布