由于elasticsearch7.x取消了type(类型的概念)对应数据库表的概念
kibana的配置以及安装地址:https://www.cnblogs.com/TJ21/p/12642219.html
添加一个索引
PUT 索引名 { "settings": { "number_of_shards": 1, "number_of_replicas": 0 } }
创建映射字段
analyzer:分词器 下载地址:https://github.com/medcl/elasticsearch-analysis-ik
PUT /索引名/_mapping { "properties": { "title":{ "type": "text", "analyzer": "ik_max_word" }, "images":{ "type": "keyword", "index": false }, "price":{ "type": "float" } } }
查看映射关系
GET /索引名/_mapping
新增数据
随机生成id
POST /索引库名/_doc { "title":"大米手机", "images":"http://image.leyou.com/12479122.jpg", "price":2899.00 }
自定义id
自定义id值不能重复,否则数据将会被覆盖
POST /索引库名/_doc/自定义id值 { "title":"超米手机", "images":"http://image.leyou.com/12479122.jpg", "price":3699.00, "Saleable":true }
修改数据,
将上面自定义id的请求方式修改
PUT /索引库/_doc/id值 { "title":"超大米手机", "images":"http://image.leyou.com/12479122.jpg", "price":3899.00, "stock": 100, "saleable":true }
删除数据
DELETE /索引库名/_doc/id值
查询
查询所有
GET /索引库名/_search
{
"query": {
"match_all": {}
}
}
响应内容:
{ "took" : 0, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 6, "relation" : "eq" }, "max_score" : 1.0, "hits" : [ { "_index" : "goods", "_type" : "_doc", "_id" : "1", "_score" : 1.0, "_source" : { "title" : "小米手机", "images" : "http://image.leyou.com/12479122.jpg", "price" : 2699.0, "Saleable" : true } }, { "_index" : "goods", "_type" : "_doc", "_id" : "mmHtSnEBVcsVh4Caiarl", "_score" : 1.0, "_source" : { "title" : "大米手机", "images" : "http://image.leyou.com/12479122.jpg", "price" : 2899.0 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "2", "_score" : 1.0, "_source" : { "title" : "超米手机", "images" : "http://image.leyou.com/12479122.jpg", "price" : 3699.0, "Saleable" : true } }, { "_index" : "goods", "_type" : "_doc", "_id" : "3", "_score" : 1.0, "_source" : { "title" : "小米电视4A", "images" : "http://image.leyou.com/12479122.jpg", "price" : 4699.0, "Saleable" : true } }, { "_index" : "goods", "_type" : "_doc", "_id" : "4", "_score" : 1.0, "_source" : { "title" : "华为手机", "subTitle" : "小米", "images" : "http://image.leyou.com/12479122.jpg", "price" : 4699.0 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "5", "_score" : 1.0, "_source" : { "title" : "oppo", "subTitle" : "小米", "images" : "http://image.leyou.com/12479122.jpg", "price" : 4899.0 } } ] } }