#查看es的健康状态
GET /_cat/health?v
#查看节点
GET /_cat/nodes?v
#查看所有的索引的信息
GET /_cat/indices?v
#新建一个索引 名称是customer pretty的作用是美化json
PUT /customer?pretty
#插入数据
PUT /customer/doc/1?pretty
{
"name": "John Doe"
}
#查询数据
GET /customer/doc/1
#删除index
DELETE /customer?pretty
#update
POST /customer/doc/1/_update?pretty
{
"doc": { "name": "Jane Doe11222" ,"age": 20 ,"ages":10 }
}
#可以加入公式
POST /customer/doc/1/_update?pretty
{
"script": "ctx._source.age = ctx._source.age / ctx._source.ages"
}
#批量指定索引插入数据
POST /customer/doc/_bulk?pretty
{"index":{"_id":"100"}}
{"name": "John Doe" }
{"index":{"_id":"200"}}
{"name": "Jane Doe" }
#更新索引为1的数据 删除索引为2的数据
POST /customer/doc/_bulk?pretty
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}
拿取测试数据
https://github.com/elastic/elasticsearch/blob/master/docs/src/test/resources/accounts.json?raw=true
测试数据是json格式拿到之后一定在最后一行加一行空行否则导入数据报错。(bb.json是自己起的json文件名称)
curl -XPOST "localhost:9200/bank/account/_bulk?pretty&refresh" --data-binary "@bb.json" -H "Content-Type: application/json"
排序查询asc 正序 desc倒叙
GET /bank/_search?sort=account_number:desc&pretty
查询所有
GET /bank/_search
{
"query": { "match_all": {} },
"sort": [
{ "account_number": "asc" }
]
}
size相当于limit ,size的默认值为10
GET /bank/_search
{
"query": { "match_all": {} },
"size": 1
}
查询10 -19
GET /bank/_search
{
"query": { "match_all": {} },
"from": 10,
"size": 10
}
sort 是对balance排序
GET /bank/_search
{
"query": { "match_all": {} },
"sort": { "balance": { "order": "desc" } }
}
按条件返回
GET /bank/_search
{
"query": { "match_all": {} },
"_source": ["account_number", "balance"]
}
条件查询
GET /bank/_search
{
"query": { "match": { "account_number": 20 } }
}
查询address 包含mill的doc
GET /bank/_search
{
"query": { "match": { "address": "mill" } }
}
mill lane or的关系
GET /bank/_search
{
"query": { "match": { "address": "mill lane" } }
}
严格匹配
GET /bank/_search
{
"query": { "match_phrase": { "address": "mill lane" } }
}
and
GET /bank/_search
{
"query": {
"bool": {
"must": [
{ "match": { "address": "mill" } },
{ "match": { "address": "lane" } }
]
}
}
}
or
GET /bank/_search
{
"query": {
"bool": {
"should": [
{ "match": { "address": "mill" } },
{ "match": { "address": "lane" } }
]
}
}
}
neither nor
GET /bank/_search
{
"query": {
"bool": {
"must_not": [
{ "match": { "address": "mill" } },
{ "match": { "address": "lane" } }
]
}
}
}
查询一个人年龄为40 但是state不是ID
GET /bank/_search
{
"query": {
"bool": {
"must": [
{ "match": { "age": "40" } }
],
"must_not": [
{ "match": { "state": "ID" } }
]
}
}
}