ElasticSearch搜索工具Kibana的使用: 1. 访问网址:ip+端口: 例如配置的虚拟机上安装了Kibana:http://192.168.211.132:5601 2. 在Dev Tools输入DSL语句: # 查询所有索引 GET /_cat/indices?v # 创建索引usr: PUT /usr # 删除索引usr: DELETE /usr # 创建映射userinfo: PUT /usr/userinfo/_mapping { "properties": { "name":{ "type": "text", "analyzer": "ik_smart", "search_analyzer": "ik_smart", "store": false }, "city":{ "type": "text", "analyzer": "ik_smart", "search_analyzer": "ik_smart", "store": false }, "age":{ "type": "long", "store": false }, "description":{ "type": "text", "analyzer": "ik_smart", "search_analyzer": "ik_smart", "store": false } } } # 新增文档数据id=1 PUT /usr/userinfo/1 { "name":"李四", "age":22, "city":"深圳", "description":"李四来自湖北武汉!" } #新增文档数据 id=2 PUT /usr/userinfo/2 { "name":"王五", "age":35, "city":"深圳", "description":"王五家住在深圳!" } #新增文档数据 id=3 PUT /usr/userinfo/3 { "name":"张三", "age":19, "city":"深圳", "description":"在深圳打工,来自湖北武汉" } #新增文档数据 id=4 PUT /usr/userinfo/4 { "name":"张三丰", "age":66, "city":"武汉", "description":"在武汉读书,家在武汉!" } #新增文档数据 id=5 PUT /usr/userinfo/5 { "name":"赵子龙", "age":77, "city":"广州", "description":"赵子龙来自深圳宝安,但是在广州工作!", "address":"广东省茂名市" } #新增文档数据 id=6 PUT /usr/userinfo/6 { "name":"赵毅", "age":55, "city":"广州", "description":"赵毅来自广州白云区,从事电子商务8年!" } #新增文档数据 id=7 PUT /usr/userinfo/7 { "name":"赵哈哈", "age":57, "city":"武汉", "description":"武汉赵哈哈,在深圳打工已有半年了,月薪7500!" } #删除文档 DELETE usr/userinfo/7 #查询数据 #查询所有 GET /usr/_search { "query": { "match_all": { } } } #根据ID查询 GET /usr/userinfo/2 #查询排序 GET /usr/_search { "query": { "match_all": { } }, "sort": [ { "age": { "order": "desc" } } ] } #分页实现 GET /usr/_search { "query":{ "match_all": {} }, "sort":{ "age":{ "order":"desc" } }, "from": 0, "size": 3 } #过滤查询-term GET _search { "query":{ "term":{ "city":"武汉" } } } #过滤查询-terms 允许多个Term GET _search { "query":{ "terms":{ "city": [ "武汉", "广州" ] } } } #过滤-range 范围过滤 #gt表示> gte表示=> #lt表示< lte表示<= GET _search { "query":{ "range": { "age": { "gte": 30, "lte": 57 } } } } #过滤搜索 exists:是指包含某个域的数据检索 GET _search { "query": { "exists":{ "field":"address" } } } #前缀匹配 prefix GET _search { "query": { "prefix": { "name": { "value": "赵" } } } } #过滤搜索 bool #must : 多个查询条件的完全匹配,相当于 and。 #must_not : 多个查询条件的相反匹配,相当于 not。 #should : 至少有一个查询条件匹配, 相当于 or。 GET _search { "query": { "bool": { "must": [ { "term": { "city": { "value": "深圳" } } }, { "range":{ "age":{ "gte":20, "lte":99 } } } ] } } } #字符串匹配 GET _search { "query": { "match": { "description": "武汉" } } } #多个域匹配搜索 GET _search { "query": { "multi_match": { "query": "深圳", "fields": [ "city", "description" ] } } } # 高亮查询 GET user/_search { "query": { "match": { "description": "武汉" } }, "highlight": { "pre_tags": "<span style=‘color:red‘>", "post_tags": "</span>", "fields": { "description": {} } } }
原文:https://www.cnblogs.com/lyle-liu/p/12669066.html