创建文档 | post | http://localhost:9200/shopping/_doc | { "title": "苹果手机", "category": "手机","images": "http://www.google.com", "price": 10999.00} | |
创建自定义id文档(第一次请求时创建,重复请求时更新) | post/put | http://localhost:9200/shopping/_doc/1001 | { "title": "苹果手机", "category": "手机","images": "http://www.google.com", "price": 10999.00} | |
创建自定义id文档(第一次请求时创建,重复请求时报已存在信息) | post/put | http://localhost:9200/shopping/_create/1002 | { "title": "苹果手机", "category": "手机","images": "http://www.google.com", "price": 10999.00} | |
查询一个文档 | get | http://localhost:9200/shopping/_doc/1001 | | |
查询所有文档 | get | http://localhost:9200/shopping/_search | | |
全量更新文档 | put | http://localhost:9200/shopping/_doc/1001 | { "title": "三星手机", "category": "手机","images": "http://www.samsung.com", "price": 11999.00} | |
局部更新文档 | post | http://localhost:9200/shopping/_update/1001 | {"doc": { "title": "三星手机"}} | |
删除文档 | delete | http://localhost:9200/shopping/_doc/1001 | | |
带条件查询文档(请求参数) | get | http://localhost:9200/shopping/_search?q=category:手机 | | |
带条件查询文档(请求体) | get | http://localhost:9200/shopping/_search | {"query": {"match": {"category": "手机"}}} | |
带条件分页查询文档(请求体) | get | http://localhost:9200/shopping/_search | {"query": {"match": {"category": "手机"}},"from": 0,"size": 2} | |
只查固定标题列查询文档(请求体) | get | http://localhost:9200/shopping/_search | {"query": {"match": {"category": "手机"}},"_source": ["title"]} | |
根据特定字段排序查询文档(请求体) | get | http://localhost:9200/shopping/_search | {"query": {"match": {"category": "手机"}},"sort": [{"price": {"order": "desc"}}]} | 5.x之后,Elasticsearch对排序、聚合所依据的字段用单独的数据结构(fielddata)缓存到内存里了,但是在text字段上默认是禁用的,如果有需要单独开启,这样做的目的是为了节省内存空间。 |
多条件查询文档(must=且)(请求体) | get | http://localhost:9200/shopping/_search | {"query": {"bool": {"must": [{"match": {"category": "手机"}}, {"match": {"price": 10999.00}}]}}} | |
多条件查询文档(should=或)(请求体) | get | http://localhost:9200/shopping/_search | {"query": {"bool": {"should": [{"match": {"title": "苹果手机"}}, {"match": {"title": "三星手机"}}]}}} | |
范围查询文档(filter)(请求体) | get | http://localhost:9200/shopping/_search | {"query": {"bool": {"should": [{"match": {"title": "苹果手机"}}, {"match": {"title": "三星手机"}}], "filter": {"range": {"price":{"gt": 11000}}}}}} | |
完全匹配查询文档(match_phrase)(请求体) | get | http://localhost:9200/shopping/_search | {"query": {"match_phrase": {"title": "三星手机"}}} | |
对结果高亮显示查询文档(hightlight)(请求体) | get | http://localhost:9200/shopping/_search | {"query": {"match_phrase": {"title": "三星手机"}}, "highlight":{"fields": {"title": {}}}} | 只能对查询的字段做高亮显示 |
聚合查询文档(aggs)(请求体) | get | http://localhost:9200/shopping/_search | {"aggs": {"price_group": {"terms": {"field": "price"}}}} | 5.x之后,Elasticsearch对排序、聚合所依据的字段用单独的数据结构(fielddata)缓存到内存里了,但是在text字段上默认是禁用的,如果有需要单独开启,这样做的目的是为了节省内存空间。 |
聚合不显示原始数据查询文档(size)(请求体) | get | http://localhost:9200/shopping/_search | {"aggs": {"price_group": {"terms": {"field": "price"}}}, "size": 0} | 1、price_group是自定义的名字;2、5.x之后,Elasticsearch对排序、聚合所依据的字段用单独的数据结构(fielddata)缓存到内存里了,但是在text字段上默认是禁用的,如果有需要单独开启,这样做的目的是为了节省内存空间。 |
聚合平均值查询文档(aggs)(请求体) | get | http://localhost:9200/shopping/_search | {"aggs": {"price_avg": {"avg": {"field": "price"}}}} | 1、price_avg是自定义的名字;2、5.x之后,Elasticsearch对排序、聚合所依据的字段用单独的数据结构(fielddata)缓存到内存里了,但是在text字段上默认是禁用的,如果有需要单独开启,这样做的目的是为了节省内存空间。 |