GET /_cat/indices?v # 增加一个索引 PUT /movies_index # 删除一个索引 DELETE /movies_index # 新增文档 PUT /movies_index/movies/1 { "id":1, "name":"operation red sea", "actorList":[ {"id":1,"name":"zhang yi"}, {"id":2, "name":"hai qing"}, {"id":3,"name":"zhang han yu"} ] } PUT /movies_index/movies/2 { "id":2, "name":"operation meigonghe river", "actorList":[ {"id":3,"name":"zhang han yu"} ] } PUT /movies_index/movies/3 { "id":3, "name":"incident red sea", "actorList":[ {"id":4,"name":"zhang chen"} ] } PUT /movies_index/movies/3 { "id":3, "name":"incident red sea", "actorList":[ {"id":3,"name":"zhang han yu"}, {"id":5,"name":"fang hong jian"} ] } GET /movies_index/movies/3 GET /_search/ { "query":{ "match": { "name": "operation red sea" } } } # 通过索引查找值 GET /movies_index/movies/1 GET /movies_index/movies/2 GET /movies_index/movies/3 # 修改整体替换 PUT /movies_index/movies/2 { "id":2, "name":"operation meigonghe river", "actorList":[ {"id":3,"name":"zhang han yu"} ] } # 查找 GET /movies_index/movies/2 # 修改整体替换 PUT /blog_index/blogs/1 { "title": "Invest Money", "body": "Please start investing money as soon...", "tags": ["money", "invest"], "published_on": "18 Oct 2017", "comments": [ { "name": "William", "age": 34, "rating": 8, "comment": "Nice article..", "commented_on": "30 Nov 2017" }, { "name": "John", "age": 38, "rating": 9, "comment": "I started investing after reading this.", "commented_on": "25 Nov 2017" }, { "name": "Smith", "age": 33, "rating": 7, "comment": "Very good post", "commented_on": "20 Nov 2017" } ] } { "id":3, "name":"incident red sea", "doubanScore":8.0, "actorList":[ {"id":4,"name":"zhang chen"} ] } # 查看修改结果 GET /movies_index/movies/3 # 修改某个字段 POST /movies_index/movies/3/_update { "doc":{ "doubanScore":9.9 } } GET /movies_index/movies/3 # 删除一个document DELETE movies_index/movies/3 # 搜索TYPE全部数据 GET /movies_index/movies/_search # 按条件查询 # 按条件查询全部 GET /movies_index/movies/_search { "query": { "match_all": {} } } # 按分词查询 GET /movies_index/movies/_search { "query": { "match": { "name": "red" } } } # 修改Id为1的数据中actorList中id为2的属性为haiqing POST /movies_index/movies/1/_update { "doc":{ "actorList": [ { "id" : 1, "name" : "zhang yi" }, { "id" : 2, "name" : "haiqing" }, { "id" : 3, "name" : "zhang han yu" }] } } GET /movies_index/movies/1 GET /movies_index/movies/2 # 按分词子属性查询 GET /movies_index/movies/_search { "query": { "match": { "name": "red sea" } } } # 按短语查询,不再利用分词技术,直接用短语在原始数据中匹配 GET /movies_index/movies/_search { "query": { "match_phrase": { "name": "red sea" } } } # fuzzy查询,校正匹配分词,当一个单词都无法准确匹配,es通过一种算法对非常接近的单词也给出一定的评分,能够查询出来,但是消耗更多的性能 GET /movies_index/movies/_search { "query":{ "fuzzy": {"name":"operatiom"} } } # 过滤 -查询后过滤 GET /movies_index/movies/_search { "query": { "match": { "name": "operation" } } } GET /movies_index/movies/_search { "query": { "match": { "name": "operation" } },"post_filter": { "term": { "actorList.id": 1 } } } # 查询前过滤V001 GET /movies_index/movies/_search { "query": { "bool": { "filter": [ {"term":{"actorList.id":3}} ] } } } # 查询前过V002 GET /movies_index/movies/_search { "query": { "bool": { "filter": [ {"term":{"actorList.id":3}}, {"term":{"actorList.id":1}} ] } } } # 查询前过滤V003 GET /movies_index/movies/_search { "query": { "bool": { "filter": [ {"term":{"actorList.id":3}}, {"term":{"actorList.id":1}} ],"must": [ {"match": { "name": "red" }} ] } } } # 增加豆瓣电影评分 POST /movies_index/movies/3/_update { "doc":{ "doubanScore":9.9 } } GET /movies_index/movies/2 GET /movies_index/movies/_search { "query": { "match_all": {} } } # 过滤按范围进行过滤 GET /movies_index/movies/_search { "query": { "bool": { "filter": { "range": { "doubanScore": { "gte": 8 } } } } } } GET /movies_index/movies/_search { "query": { "match": { "name": "red" } },"sort": [ { "doubanScore": { "order": "desc" } } ] } GET /movies_index/movies/_search { "query": { "match_all": {} } ,"sort": [ { "doubanScore": { "order": "desc" } } ] } GET /movies_index/movies/_search { "query": { "match_all": {} },"sort": [ { "doubanScore": { "order": "asc" } } ] } # 分页查询 GET /movies_index/movies/_search { "query": {"match_all": {}}, "from": 1, "size": 1 } # 指定查询的字段 GET /movies_index/movies/_search { "query": {"match_all": {}}, "_source": ["name","doubanScore"], "sort": [ { "doubanScore": { "order": "asc" } } ], "from": 0, "size": 10 } GET /movies_index/movies/_search { "query": {"match": { "name": "red sea" }}, "highlight": { "fields": {"name":{}} } } GET /movies_index/movies/_search { "query": {"match_all": {}}, "aggs": { "aggs_by_event_type": { "terms": { "field": "event_type" } } } } GET /movies_index/movies/_search { "query": {"match_all": {}} } # 聚合,取出每个演员一共从参加了多少部电影 GET /movies_index/movies/_search { "query": { "match_phrase": { "event_type_path": "/事件类型/恶意样本/" } } } # 每个演员参演的电影的平均分,并按评分排序 GET /movies_index/movies/_search { "aggs": { "groupby_actor_id": { "terms": { "field": "actorList.name.keyword", "order": { "avg_score": "desc" } }, "aggs": { "avg_score": { "avg": { "field": "doubanScore" } } } } } } GET /fmall_dau/_doc/_search { "aggs":{ "groupby_logDate":{ "terms":{ "field":"logDate" } } } }