乱读天书, 不求甚解
周祎骏的个人云笔记
Toggle navigation
乱读天书, 不求甚解
主页
Linux:系统配置
Linux:用户管理
Linux:优化排错
Linux:进程调度
Linux:文件系统
Linux:网络
Linux:系统服务
Linux:安全
Linux:内核
容器:Docker
容器:containerd
容器编排:Kubernetes
IAC:Terraform
大数据:Hadoop
大数据:Zookeeper
大数据:Hbase
消息队列:rsyslog
消息队列:kafka
数据库:MySQL
数据库:MongoDB
搜索引擎:Elasticsearch
时序数据库:OpenTSDB
网站服务:Nginx
编程:Bash
编程:Perl
编程:Python
编程:C
编程:JAVA
编程:Rust
版本控制:gitlab
知识管理:docusaurus
常用小工具
关于我
标签
Elasticsearch 1.1 更多搜索技巧
2016-12-27 14:54:10
116
0
0
admin
> 这里详细介绍Elasticsearch 的query #一些小技巧 ##设置timeout 为1分钟 ``` curl localhost:9200/index/type/id?timeout=1m ``` ##pretty 使显示的json 更整齐,可读 ``` curl localhost:9200/index/type/id?pretty ``` ##human 使一些信息更可读,(单位上的更可读,如ls -lh ) ``` curl localhost:9200/index/type/id?human ``` ##显示java的详细报错 ``` curl localhost:9200/index/type/id?error_trace ``` ##定制输出的内容(filter) **只显示_nodes.total,cluster_name,\*\*.successful,nodes.\*.timestamp** ``` curl 'localhost:9200/_nodes/stats?pretty&filter_path=_nodes.total,cluster_name,**.successful,nodes.*.timestamp' #其中* 可以补全、匹配任何field, ** 可以匹配任何路径(这里指xx.xx.xx.field) ``` **只显示source** ``` curl 'localhost:9200/index/type/id/_source' ``` **想要显示source 中哪些field** ``` curl 'localhost:9200/xx/xx/xx?pretty&_source_include=xx&_source_exclude=xx' curl 'localhost:9200/index/type/id?pretty&_source=xx,xx' ``` *** #常用query ##匹配所有 match_all ``` GET /index/_search { "query": { "match_all": {} }, #匹配所有 "_source": ["field1", "field2"], #只显示field1 field2 "size": 100, #列出100个,默认10 "from": 10, #从第10个开始显示,默认是0,用于分页 "sort": { "field": "desc" } } #对某个field 来排序 } ``` ##匹配某些字符串,会分词 match ``` GET /index/_search { "query": { "match": { "field": "word1 word2" } } #搜索field 中包含word1 或者word2 的文档 } ``` ``` GET /index/_search { "query": { "match": { "field": 1 } } #搜索field = 1 的文档 } ``` ##匹配某些字符串,不会分词 match_phrase ``` GET /index/_search { "query": { "match_phrase": { "field": "word1 word2" } } #搜索field 中包含"word1 word2"的文档 } ``` ##复合查询 bool ``` GET /index/_search { "query": { "bool": { "must/should": [ #must 表示&&,要都满足才匹配;should 表示||,有一个满足就可以了 { "match": { "field1": "word1" } }, { "match": { "field2": "word2" } } ], "must_not": [ #必须都不满足 { "match": { "field3": "word3" } }, { "match": { "field4": "word4" } } ], "filter": { "range": { #拿 10 <= field5 <= 30 的 "field5": { "gte": 10, "lte": 30 } } } } } } ```
上一篇:
Elasticsearch 1.0 简单的增删改查
下一篇:
Elasticsearch 1.2 多库同时搜索
文档导航