# EsProject **Repository Path**: gitliuxm/EsProject ## Basic Information - **Project Name**: EsProject - **Description**: No description available - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-03-20 - **Last Updated**: 2021-09-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 查看分词 GET /_analyze { "analyzer": "ik_max_word", "text": "酷派 8076D 咖啡棕 移动3G手机 双卡双待" } # 索引库操作 put /heima get /heima delete /heima # 映射操作 put /heima { "mappings":{ "properties":{ "title":{ "type":"text", "index":"true", "analyzer":"ik_max_word" }, "images":{ "type":"keyword", "index":"false" }, "price":{ "type":"float" } }, "dynamic_templates":[{ "strings":{ "match_mapping_type":"string", "mapping":{ "type":"keyword" } } }] } } get /heima/_mapping put /heima/_mapping { "properties":{ "title":{ "type":"text", "index":"true", "analyzer":"ik_max_word" }, "images":{ "type":"keyword", "index":"false" }, "price":{ "type":"float", "index":"true" } } } # 文档操作 post /heima/_doc/1 { "title":"小米手机", "images":"http://image.leyou.com/12479122.jpg", "price":2699.0 } get /heima/_doc/1 put /heima/_doc/1 { "title":"华为手机", "images":"http://image.leyou.com/12479122.jpg", "price":5888.0 } delete /heima/_doc/1 # 查询操作 #1.查询所有数据 get /heima/_search { "query":{ "match_all": {} } } #2.分词查询数据 get /heima/_search { "query":{ "match": { "title": { "query": "酷派 8076D 咖啡棕 移动3G手机 双卡双待", "operator": "and" } } } } #3.词条查询数据 get /heima/_search { "query":{ "term": { "title":{ "value": "三星" } } } } #4.模糊查询数据 可以设置偏差量 get /heima/_search { "query":{ "fuzzy": { "title": { "value": "飞利普", "fuzziness": 1 } } } } #5.范围查询数据 get /heima/_search { "query":{ "range": { "price": { "gte": 1000, "lte": 5000 } } } } #6.多条件查询 title price not get /heima/_search { "query":{ "bool": { "must": [ { "match": { "title": "手机" } }, { "range": { "price": { "gte": 1000, "lte": 5000 } } } ], "must_not": [ { "term": { "title": { "value": "三星" } } } ] } } } #7.过滤查询 get /heima/_search { "query":{ "bool": { "must": [ { "match": { "title": "手机" } } ], "filter": [ { "range": { "price": { "gte": 1000, "lte": 5000 } } } ], "must_not": [ { "term": { "title": { "value": "三星" } } } ] } } } # 排序与分页 get /heima/_search { "query":{ "match_all": {} }, "sort":[{ "price":{ "order":"desc" } }], "from":0, "size":2 } # 高亮 get /heima/_search { "query":{ "match": { "title": "三星手机" } }, "highlight":{ "pre_tags": "
", "post_tags": "
", "fields": { "title": {} } } } # 筛选 get /heima/_search { "_source":{ "includes":["title","images"] } } get /heima/_search { "_source":{ "exclude":["title","images"] } } # 聚合 get /car/_search { "size":0, "aggs":{ "stats_price":{ "stats": { "field": "price" } } } } # 聚合桶 get /car/_search { "aggs":{ "terms_by_color":{ "terms": { "field": "color" } } }, "size":0 } # 聚合度量 get /car/_search { "aggs":{ "terms_by_color":{ "terms": { "field": "color" }, "aggs": { "avg_by_color": { "avg": { "field": "price" } } } } }, "size":0 } # 嵌套 get /car/_search { "aggs":{ "terms_by_color":{ "terms": { "field": "color" }, "aggs": { "avg_by_color": { "avg": { "field": "price" } }, "terms_by_make":{ "terms": { "field": "make" } } } } }, "size":0 } get /car/_search { "query":{ "match_all": {} } } POST /car/_bulk { "index": {}} { "price" : 10000, "color" : "红", "make" : "本田", "sold" : "2014-10-28" } { "index": {}} { "price" : 20000, "color" : "红", "make" : "本田", "sold" : "2014-11-05" } { "index": {}} { "price" : 30000, "color" : "绿", "make" : "福特", "sold" : "2014-05-18" } { "index": {}} { "price" : 15000, "color" : "蓝", "make" : "丰田", "sold" : "2014-07-02" } { "index": {}} { "price" : 12000, "color" : "绿", "make" : "丰田", "sold" : "2014-08-19" } { "index": {}} { "price" : 20000, "color" : "红", "make" : "本田", "sold" : "2014-11-05" } { "index": {}} { "price" : 80000, "color" : "红", "make" : "宝马", "sold" : "2014-01-01" } { "index": {}} { "price" : 25000, "color" : "蓝", "make" : "福特", "sold" : "2014-02-12" }