欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ElasticSearch基本使用

程序员文章站 2022-03-05 09:54:17
...
#查看集群健康状态
GET /_cat/health?v
#查看集群节点
GET /_cat/nodes?v
#查看所有索引
GET /_cat/indices?v
#删除索引
DELETE /test?pretty
#创建索引
PUT /test2
 {
            "settings": {
            "number_of_shards" :   1,
            "number_of_replicas" : 0
            }
}

get test2

#查看索引中的mapping
GET test2/_mapping

#新江mapping数据 b相当于表名
#properties中key为字段名称val实是属性和类型和其他配置
POST test2/b/_mapping?pretty
{
	"b": {
		"properties": {
			"title": {"type": "text","store": "true"},
			"description": {"type": "text","index": "false"},
			"price": {"type": "double"},
			"onSale": {"type": "boolean"},
			"type": {"type": "integer"},
			"createDate": {"type": "date"}
		}
	}
}

POST test2/b
{
  "title": "zhangsan",
  "description": "this is a random desc ",
  "price": 22.6,
  "onSale": "true",
  "type": 2,
  "createDate": "2018-01-12"
}

PUT /test

#批处理 新增数据
POST /test/doc/_bulk?pretty
{"index":{"_id":"1"}}
{"name": "JohnDoe" ,"age":10}
{"index":{"_id":"2"}}
{"name": "zhangsan" ,"age":15}
{"index":{"_id":"3"}}
{"name": "zhangsan" ,"age":16}
{"index":{"_id":"4"}}
{"name": "zhangsan1" ,"age":16}

#分页排序查询
GET /test/_search
{
  "query": { "match_all": {} },
  "from": 1,
  "size": 2,
  "sort":[
    {"age":"asc"}
    ]
}

#条件查询
GET /test/_search
{
  "query": { "match": { "name": "zhangsan John" } }
}

#集合查询相当于 group by
GET /test/_search
{
      "size": 0,
      "aggs": {
        "group_by_state": {
          "terms": {
            "field": "age"
          }
        }
      }
    }

未完待续。。。。

相关标签: ElasticSearch