Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

8.3. 搜索

搜索所有内容

# curl -XGET 'http://localhost:9200/_search?pretty'	
# curl -XGET 'http://localhost:9200/_all/_search?pretty'			
		

指定 _index 搜索

# curl -XGET 'http://localhost:9200/website/_search?pretty'
# curl -XGET 'http://localhost:9200/website/news/_search?pretty'
		

指定 _type 搜索

# curl -XGET 'http://localhost:9200/website,twitter/_search?pretty'
# curl -XGET 'http://localhost:9200/website/news,blog/_search?pretty'
# curl -XGET 'http://localhost:9200/website,twitter/news,blog/_search?pretty'
		

所有 _index 包含指定 _type 搜索

# curl -XGET 'http://localhost:9200/_all/news,blog/_search?pretty'
		

8.3.1. URL 搜索

字符串搜索

			
# curl -XGET 'http://localhost:9200/_all/_search?q=neo&pretty'
			
			

同时满足两个条件

+name:neo +age:30
			

查找name为mary 或者 john的数据

+name:(mary john)
			

查询姓名是neo或者jam并且年龄小于30岁同时1980-09-10之后出生的

			
+name:(neo jam) +age:<30 +date:>1980-09-10
			
			

8.3.2. 分页

该功能与SQL的LIMIT关键字结果一样,Elasticsearch接受size和from两个参数参数:

size: 返回结果集数量,默认10,用法与SQL中的 Limit相同

from: 偏移量,默认0,用法与 SQL中的 Offset相同

如果你想每页显示10个结果,那么请求如下:

			
第一页 GET /_search?size=10
第二页 GET /_search?size=10&from=10
第三页 GET /_search?size=10&from=20