https://www.elastic.co/cn/downloads/elasticsearch
添加内容:
curl -X PUT "
http://localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d' {"name": "赵莉贤"}'
查找:
curl -X GET "localhost:9200/customer/_doc/1?pretty"
测试:
批量上传数据:curl -H "Content-Type: application/json" -X POST "localhost:9200/bank/_bulk?pretty&refresh" --data-binary "@accounts.json"
查看数据:curl "localhost:9200/_cat/indices?v=true"

按顺序查找:
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": { "match_all": {} },
"sort": [
{ "account_number": "asc" }
]
}
'
"grant_type":"authorization_code",
"code":"NE325Y",
"client_id":"usermessage-provider"
"Authorization": "Basic dXNlcm1lc3NhZ2UtcHJvdmlkZXI6MTIzNDU2"
}'
usermessage-provider:123456 base64-> dXNlcm1lc3NhZ2UtcHJvdmlkZXI6MTIzNDU2
curl -X POST "localhost:1113/oauth/token" -d "grant_type=password&username=123&password=123&Authorization=Basic dGVzdDE6dGVzdDExMTE=&scope=all"
curl -X POST "localhost:8080/oauth/token" -d "grant_type=password&username=123&password=123456&Authorization=Basic dGVzdDE6dGVzdDExMTE=&scope=all"
分页查询:
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": { "match_all": {} },
"sort": [
{ "account_number": "asc" }
],
"from": 10,
"size": 10
}
'
根据字段查询,模糊查询,只要包含mill,lane:
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": { "match": { "address": "mill lane" } }
}
'
按照短语模糊查找:
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": { "match_phrase": { "address": "mill lane" } }
}
'
多条件查询
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"bool": {
"must": [
{ "match": { "age": "40" } }
],
"must_not": [
{ "match": { "state": "ID" } }
]
}
}
}
'
过滤:
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"bool": {
"must": { "match_all": {} },
"filter": {
"range": {
"balance": {
"gte": 20000,
"lte": 30000
}
}
}
}
}
}
'
聚和操作分组:
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
"size": 0,
"aggs": {
"group_by_state": {
"terms": {
"field": "state.keyword"
}
}
}
}
'
分组state求平均值balance:
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
"size": 0,
"aggs": {
"group_by_state": {
"terms": {
"field": "state.keyword"
},
"aggs": {
"average_balance": {
"avg": {
"field": "balance"
}
}
}
}
}
}
'
聚合中指定顺序来使用嵌套聚合的结果进行排序
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
"size": 0,
"aggs": {
"group_by_state": {
"terms": {
"field": "state.keyword",
"order": {
"average_balance": "desc"
}
},
"aggs": {
"average_balance": {
"avg": {
"field": "balance"
}
}
}
}
}
}
'
全文查询
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"match": {
"message": {
}
}
}
}
'