Elasticsearch提供了很多使用的函数来更加方便的满足不用的场景需求。
preference,搜索分片副本执行偏好设置。默认情况下,使用随机副本方法搜索副本的分片。可以通过preference参数设置搜索分片的范围。例如:
请求:POST http://127.0.0.1:9200/secilog/_search?_primary
参数:
{ "query": { "match": { "message": "POST " } } }
这个值也可以是一个自定义的值,它将被用来保证同样的分片将使用相同的自定义值,这个值可以是网络会话标识,或用户名称。例如:请求:POST http://127.0.0.1:9200/secilog/_search?preference=xyzabc123。
版本号version:通过"version": true可以对每个返回的之中有版本号。
{ "version": true, "query" : { "term" : { "message": "POST" } } }
索引加速Index Boost :当搜索一个以上的索引的时候,可以对每个索引配置不同的索引加速级别。当有多个索引存储类似的文档的时候,一个索引的命中级别高于另一个索引的时候非常有用,例如:
{ "indices_boost" : { "index1" : 1.4, "index2" : 1.3 } }
最小分值min_score:可以指定搜索时候的最小评分的分值。例如:
{ "min_score": 0.5, "query" : { "term" : { "message": "POST" } } }
分值解释explain:可以使每个命中的查询解释它的得分是如何计算出来的。
{ "explain": true, "query": { "term": { "message": "copyright" } } }
分片情况查询,例如:
请求:GET http://127.0.0.1:9200/secilog/_search_shards/
总数查询:例如:
请求:POST http://127.0.0.1:9200/secilog/_count/
参数:
{ "explain": true, "query": { "term": { "message": "copyright" } } }
返回结果:
{ "count": 1, "_shards": { "total": 5, "successful": 5, "failed": 0 } }
是否存在查询:
请求:POST http://127.0.0.1:9200/customer/_search/
参数:
{ "query": { "term": { "state": "close" } }, "size": 0, "terminate_after": 1 }
返回的结果:
{ "took": 2, "timed_out": false, "terminated_early": true, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 2, "max_score": 0, "hits": [ ] } }
验证接口:验证接口允许用户验证一个查询的语法是否正确,这样可以不用实际执行,可以提高效率,防止误操作。例如:
请求:POST http://127.0.0.1:9200/customer/_validate/query/
参数:
{ "query": { "term": { "state": "close" } } }
返回结果:
{ "valid": true, "_shards": { "total": 1, "successful": 1, "failed": 0 } }
列字段状态查询:
请求:GET http://127.0.0.1:9200/customer/_field_stats/
结果:
{ "_shards": { "total": 5, "successful": 5, "failed": 0 }, "indices": { "_all": { "fields": { "state": { "max_doc": 5, "doc_count": 5, "density": 100, "sum_doc_freq": 5, "sum_total_term_freq": 5, "min_value": "close", "max_value": "open" } } } } }
赛克蓝德(secisland)后续会逐步对Elasticsearch的最新版本的各项功能进行分析,近请期待。也欢迎加入secisland公众号进行关注。