5、Kibana操作ElasticSearch7.6.x
elasticsearch7.x取消了type(类型的概念)对应数据库表的概念,指定不指定都可以
1、创建索引和文档
PUT 索引名 { "settings": { "number_of_shards": 1, "number_of_replicas": 0 } }
PUT /索引名/~类型~(可以不写)/id(不写的话是随机生成) { "name":"张三" }
PUT 索引名 { "mappings": { "properties": { "name":{ "type": "text" }, "age":{ "type": "long" }, "birthday":{ "type": "date" } } } }
2、更新文档
推荐使用POST更新
#更新数据-PUT如果没有指定字段,会把之前的数据覆盖,相当于mysql中的replace PUT /movie/_doc/1 { "purchase_name" : "嘻哈英熊", "director" : "王琦", "asset_year" : "2017", "set_duration" : 1, "synopsis" : "洗好澡真搞笑" } #POST更新,不会覆盖,推荐使用 POST /{index}/_update/{id} POST /movie/_update/1 { "doc":{ "director":"王琦,葛优" } }
3、删除索引和文档
#删除一个索引 DELETE {index}
#删除指定id DELETE {index}/_doc/{id}
4、查询
包括模糊查询、精确查询、条件查询、分页、排序、高亮查询
GET /索引名/类型(默认_doc)/id
#条件查询 = SELECT * FROM movie WHERE purchase_name = '%s' GET 索引/_search { "query": { "match": { "{FIELD}": "大" } } }
#条件查询 SELECT purchase_name, director FROM movie WHERE purchase_name = '%s' GET movie/_search { "query": { "match": { "purchase_name": "大" } }, "_source": ["purchase_name", "director"] }
#排序 order_by GET 索引名/_search { "query": { "match": { "purchase_name": "大" } }, "sort": [ { "{FIELD}": { "order": "desc" } } ] }
#分页查询----limit限制显示数据-- from从第几个开始, size返回多少条数据 GET 索引名/_search { "query": { "match": { "purchase_name": "大" } }, "from": 0, "size": 1 }
#布尔值查询must 多条件查询 and GET movie/_search { "query": { "bool": { "must": [ { "match": { "purchase_name": "大家" } }, { "match": { "asset_year": "1991" } } ] } } }
#should -or GET movie/_search { "query": { "bool": { "should": [ { "match": { "purchase_name": "大" } }, { "match": { "asset_year": "1991" } } ] } } }
#filter 过滤 gte大于等于 lte小于等于 GET movie/_search { "query": { "bool": { "should": [ { "match": { "purchase_name": "大" } }, { "match": { "asset_year": "1991" } } ], "filter": { "range": { "set_duration": { "gte": 1, "lte": 20 } } } } } }
#精确查询term直接通过倒排索引指定的词条进行精确查找 #关于分词, term直接精确查询 , match, 使用分词器解析,(先分析分档,在通过分析的文档查询 #俩个类型 text和keyword, keyword类型的字段不会被分词器解析 GET movie/_search { "query": { "term": { "FIELD": { "value": "VALUE" } } } }
#高亮查询 tags中写css样式 GET movie/_search { "query": { "match": { "FIELD": "TEXT" } }, "highlight": { "pre_tags": "", "post_tags": "", "fields": { "purchase_name": {} } } }